Search in sources :

Example 46 with ClassMetadata

use of org.hibernate.metadata.ClassMetadata in project BroadleafCommerce by BroadleafCommerce.

the class DynamicDaoHelperImpl method getPropertyTypes.

@Override
public List<Type> getPropertyTypes(Class<?> entityClass, HibernateEntityManager entityManager) {
    entityClass = getNonProxyImplementationClassIfNecessary(entityClass);
    ClassMetadata metadata = getSessionFactory(entityManager).getClassMetadata(entityClass);
    List<Type> propertyTypes = new ArrayList<>();
    Collections.addAll(propertyTypes, metadata.getPropertyTypes());
    return propertyTypes;
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) Type(org.hibernate.type.Type) ArrayList(java.util.ArrayList)

Example 47 with ClassMetadata

use of org.hibernate.metadata.ClassMetadata in project BroadleafCommerce by BroadleafCommerce.

the class DynamicDaoHelperImpl method getIdField.

@Override
public Field getIdField(Class<?> clazz, Session session) {
    clazz = getNonProxyImplementationClassIfNecessary(clazz);
    ClassMetadata metadata = session.getSessionFactory().getClassMetadata(clazz);
    Field idField = ReflectionUtils.findField(clazz, metadata.getIdentifierPropertyName());
    idField.setAccessible(true);
    return idField;
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) Field(java.lang.reflect.Field)

Example 48 with ClassMetadata

use of org.hibernate.metadata.ClassMetadata in project BroadleafCommerce by BroadleafCommerce.

the class DynamicDaoHelperImpl method getIdMetadata.

@Override
public Map<String, Object> getIdMetadata(Class<?> entityClass, HibernateEntityManager entityManager) {
    entityClass = getNonProxyImplementationClassIfNecessary(entityClass);
    Map<String, Object> response = new HashMap<>();
    SessionFactory sessionFactory = entityManager.getSession().getSessionFactory();
    ClassMetadata metadata = sessionFactory.getClassMetadata(entityClass);
    if (metadata == null) {
        return null;
    }
    String idProperty = metadata.getIdentifierPropertyName();
    response.put("name", idProperty);
    Type idType = metadata.getIdentifierType();
    response.put("type", idType);
    return response;
}
Also used : SessionFactory(org.hibernate.SessionFactory) ClassMetadata(org.hibernate.metadata.ClassMetadata) Type(org.hibernate.type.Type) HashMap(java.util.HashMap)

Example 49 with ClassMetadata

use of org.hibernate.metadata.ClassMetadata in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateClassMetadata.

@Test
public void testCreateClassMetadata() {
    ClassMetadata classMetadata = (ClassMetadata) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { ClassMetadata.class }, new TestInvocationHandler());
    IClassMetadata facade = facadeFactory.createClassMetadata(classMetadata);
    assertSame(classMetadata, ((IFacade) facade).getTarget());
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata) PersistentClass(org.hibernate.mapping.PersistentClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) POJOClass(org.hibernate.tool.hbm2x.pojo.POJOClass) Test(org.junit.jupiter.api.Test)

Example 50 with ClassMetadata

use of org.hibernate.metadata.ClassMetadata in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateClassMetadata.

@Test
public void testCreateClassMetadata() {
    ClassMetadata classMetadata = (ClassMetadata) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { ClassMetadata.class }, new TestInvocationHandler());
    IClassMetadata facade = facadeFactory.createClassMetadata(classMetadata);
    assertSame(classMetadata, ((IFacade) facade).getTarget());
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata) IClassMetadata(org.jboss.tools.hibernate.runtime.spi.IClassMetadata) PersistentClass(org.hibernate.mapping.PersistentClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) POJOClass(org.hibernate.tool.hbm2x.pojo.POJOClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) Test(org.junit.jupiter.api.Test)

Aggregations

ClassMetadata (org.hibernate.metadata.ClassMetadata)58 PersistentClass (org.hibernate.mapping.PersistentClass)23 IClassMetadata (org.jboss.tools.hibernate.runtime.spi.IClassMetadata)21 RootClass (org.hibernate.mapping.RootClass)20 IPOJOClass (org.jboss.tools.hibernate.runtime.spi.IPOJOClass)12 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)12 POJOClass (org.hibernate.tool.hbm2x.pojo.POJOClass)11 Test (org.junit.jupiter.api.Test)11 Type (org.hibernate.type.Type)10 Before (org.junit.Before)8 Field (java.lang.reflect.Field)5 AbstractEntityPersister (org.hibernate.persister.entity.AbstractEntityPersister)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Session (org.hibernate.Session)4 SessionFactory (org.hibernate.SessionFactory)4 SessionImpl (org.hibernate.internal.SessionImpl)4 ComponentType (org.hibernate.type.ComponentType)4 AbstractClassMetadataFacade (org.jboss.tools.hibernate.runtime.common.AbstractClassMetadataFacade)4 MasterDataEntity (org.mifos.application.master.business.MasterDataEntity)4