Package org.hibernate.metadata

Examples of org.hibernate.metadata.ClassMetadata


        try {
            Class valueClass = ClickUtils.classForName(classField.getValue());

            String classname = getClassname(valueClass);

            ClassMetadata metadata = getSessionFactory().getClassMetadata(classname);

            String[] propertyNames = metadata.getPropertyNames();

            boolean[] propertyNullability = metadata.getPropertyNullability();

            for (int i = 0; i < propertyNames.length; i++) {
                Field field = getField(propertyNames[i]);
                if (field != null) {
                    boolean isMandatory = !propertyNullability[i];
View Full Code Here


    if (null != sessionFactory && entityTypes.isEmpty()) {
      StopWatch watch = new StopWatch();
      watch.start();
      Map<String, ClassMetadata> classMetadatas = sessionFactory.getAllClassMetadata();
      for (Iterator<ClassMetadata> iter = classMetadatas.values().iterator(); iter.hasNext();) {
        ClassMetadata cm = (ClassMetadata) iter.next();
        buildEntityType(sessionFactory, cm.getEntityName());
      }
      logger.info("Find {} entities,{} collections from hibernate in {} ms",
          new Object[] { entityTypes.size(), collectionTypes.size(), watch.getTime() });
      if (logger.isDebugEnabled()) {
        loggerTypeInfo();
View Full Code Here

   * @return
   */
  private EntityType buildEntityType(SessionFactory sessionFactory, String entityName) {
    EntityType entityType = (EntityType) entityTypes.get(entityName);
    if (null == entityType) {
      ClassMetadata cm = sessionFactory.getClassMetadata(entityName);
      if (null == cm) {
        logger.error("Cannot find ClassMetadata for {}", entityName);
        return null;
      }
      entityType = new EntityType();
      entityType.setEntityName(cm.getEntityName());
      entityType.setIdPropertyName(cm.getIdentifierPropertyName());
      entityType.setEntityClass(cm.getMappedClass(EntityMode.POJO));
      entityTypes.put(cm.getEntityName(), entityType);

      Map<String, Type> propertyTypes = entityType.getPropertyTypes();
      String[] ps = cm.getPropertyNames();
      for (int i = 0; i < ps.length; i++) {
        org.hibernate.type.Type type = cm.getPropertyType(ps[i]);
        if (type.isEntityType()) {
          propertyTypes.put(ps[i], buildEntityType(sessionFactory, type.getName()));
        } else if (type.isComponentType()) {
          propertyTypes.put(ps[i], buildComponentType(sessionFactory, entityName, ps[i]));
        } else if (type.isCollectionType()) {
View Full Code Here

    if (null != entityType) {
      Type propertyType = (Type) entityType.getPropertyTypes().get(propertyName);
      if (null != propertyType) { return (ComponentType) propertyType; }
    }

    ClassMetadata cm = sessionFactory.getClassMetadata(entityName);
    org.hibernate.type.ComponentType hcType = (org.hibernate.type.ComponentType) cm
        .getPropertyType(propertyName);
    String[] propertyNames = hcType.getPropertyNames();

    ComponentType cType = new ComponentType(hcType.getReturnedClass());
    Map<String, Type> propertyTypes = cType.getPropertyTypes();
    for (int j = 0; j < propertyNames.length; j++) {
      org.hibernate.type.Type type = cm.getPropertyType(propertyName + "." + propertyNames[j]);
      if (type.isEntityType()) {
        propertyTypes.put(propertyNames[j], buildEntityType(sessionFactory, type.getName()));
      } else if (type.isComponentType()) {
        propertyTypes
            .put(propertyNames[j],
View Full Code Here

   
    // TODO May still need to convert non-strings to the correct value (ie long to double, etc).
    if (!(value instanceof String)) {
      return value;
    }   
    ClassMetadata metadata = hibernateUtil.getSessionFactory().getClassMetadata(clazz);
    if (metadata != null) {
      Type type = metadata.getPropertyType(fieldName);
      if (type instanceof CollectionType) {
        log.warn("Unable to handle collection: " + fieldName);
        return value;
      } else if (type instanceof AssociationType) {
        AssociationType assocType = (AssociationType)type;
View Full Code Here

        DetachedCriteria subC = joins.get(joinPath);
        if (subC == null) {
          subC = c.createCriteria(joinProperty, joinPath, Criteria.LEFT_JOIN);
          joins.put(joinPath, subC);
        }
        ClassMetadata metadata = hibernateUtil.getSessionFactory().getClassMetadata(searchClass);
        Type type = metadata.getPropertyType(joinProperty);
        if (type instanceof CollectionType) {
          log.info("Expiremental CollectionType join: " + joinPath);
          subC.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
          Type newtype = ((CollectionType)type).getElementType((SessionFactoryImplementor)hibernateUtil.getSessionFactory());
          searchClass = newtype.getReturnedClass();
View Full Code Here

                logger.debug("Force initialization of " + objClass.getName());
            }

            Hibernate.initialize(obj);

            final ClassMetadata classMetadata = getSessionFactory().getClassMetadata(objClass);

            if (classMetadata == null)
            {
                return;
            }

            for (int index = 0, size = classMetadata.getPropertyNames().length; index < size; index++)
            {
                final String propertyName = classMetadata.getPropertyNames()[index];
                final Type type = classMetadata.getPropertyType(propertyName);

                if (type.isEntityType())
                {
                    final Object propertyValue = classMetadata.getPropertyValue(obj, propertyName, EntityMode.POJO);

                    if (!Hibernate.isInitialized(propertyValue))
                    {
                        initialize(propertyValue);
                    }
                }
                else if (type.isCollectionType())
                {
                    final Collection<?> collection = (Collection<?>) classMetadata.getPropertyValue(
                            obj,
                            propertyName,
                            EntityMode.POJO);

                    Hibernate.initialize(collection);
View Full Code Here

      return PersistenceUtilHelper.isLoaded( entity ) != LoadState.NOT_LOADED;
    }

    public Object getIdentifier(Object entity) {
      final Class entityClass = Hibernate.getClass( entity );
      final ClassMetadata classMetadata = emf.getSessionFactory().getClassMetadata( entityClass );
      if (classMetadata == null) {
        throw new IllegalArgumentException( entityClass + " is not an entity" );
      }
      //TODO does that work for @IdClass?
      return classMetadata.getIdentifier( entity );
    }
View Full Code Here

        valueClass = valueClass.getSuperclass();
      }

      SessionFactory sessionFactory = jbpmContext.getSessionFactory();
      if (sessionFactory!=null) {
        ClassMetadata classMetadata = sessionFactory.getClassMetadata(valueClass);
        matches = ( (classMetadata!=null)
                    && (classMetadata.getIdentifierType().getClass()==StringType.class)
                   );
      }
    } else {
      log.debug("no current context so valueClass cannot be stored as a string-id-ref to a hibernate object");
      matches = false;
View Full Code Here

        valueClass = valueClass.getSuperclass();
      }
     
      SessionFactory sessionFactory = jbpmContext.getSessionFactory();
      if (sessionFactory!=null) {
        ClassMetadata classMetadata = sessionFactory.getClassMetadata(valueClass);
        matches =  ( (classMetadata!=null)
                     && (classMetadata.getIdentifierType().getClass()==LongType.class)
                   );
      }
    } else {
      log.debug("no current context so valueClass cannot be stored as a long-id-ref to a hibernate object");
      matches = false;
View Full Code Here

TOP

Related Classes of org.hibernate.metadata.ClassMetadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.