Search in sources :

Example 6 with ClassMetadata

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

the class ImmutableEntityNaturalIdTest method testMappingProperties.

@Test
public void testMappingProperties() {
    ClassMetadata metaData = sessionFactory().getClassMetadata(Building.class);
    assertTrue("Class should have a natural key", metaData.hasNaturalIdentifier());
    int[] propertiesIndex = metaData.getNaturalIdentifierProperties();
    assertEquals("Wrong number of elements", 3, propertiesIndex.length);
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) Test(org.junit.Test)

Example 7 with ClassMetadata

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

the class TableCommentTest method getTableName.

private String getTableName() {
    SessionFactoryImplementor sessionFactoryImplementor = sessionFactory();
    ClassMetadata tableWithCommentMetadata = sessionFactoryImplementor.getClassMetadata(TableWithComment.class);
    return ((AbstractEntityPersister) tableWithCommentMetadata).getTableName();
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister)

Example 8 with ClassMetadata

use of org.hibernate.metadata.ClassMetadata in project yyl_example by Relucent.

the class HibernateTest method test3.

private static void test3(SessionFactory sessionFactory) {
    System.out.println("--------------------------------------------------");
    ClassMetadata metadata = sessionFactory.getClassMetadata(Table1.class);
    System.out.println("EntityName: " + metadata.getMappedClass());
    System.out.println("IdProperty: " + metadata.getIdentifierPropertyName());
    for (String propertyName : metadata.getPropertyNames()) {
        Type type = metadata.getPropertyType(propertyName);
        System.out.println("Property: " + propertyName);
        System.out.println(" isComponentType: " + type.isComponentType());
        System.out.println(" isAnyType: " + type.isAnyType());
        System.out.println(" isCollection: " + type.isCollectionType());
        System.out.println(" isAssociationType: " + type.isAssociationType());
        if (type instanceof AssociationType) {
            AssociationType associationType = (AssociationType) type;
            String associatedEntityName = associationType.getAssociatedEntityName((SessionFactoryImpl) sessionFactory);
            ClassMetadata associatedClassMetadata = sessionFactory.getClassMetadata(associatedEntityName);
            Class<?> mappedClass = associatedClassMetadata.getMappedClass();
            System.out.println(" associatedClass: " + mappedClass);
        } else {
            System.out.println(" propertyClass: " + type.getReturnedClass());
        }
        System.out.println();
    }
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) AssociationType(org.hibernate.type.AssociationType)

Example 9 with ClassMetadata

use of org.hibernate.metadata.ClassMetadata in project midpoint by Evolveum.

the class RUtil method fixCompositeIdentifierInMetaModel.

private static void fixCompositeIdentifierInMetaModel(SessionFactory sessionFactory, Class clazz) {
    ClassMetadata classMetadata = sessionFactory.getClassMetadata(clazz);
    if (classMetadata instanceof AbstractEntityPersister) {
        AbstractEntityPersister persister = (AbstractEntityPersister) classMetadata;
        EntityMetamodel model = persister.getEntityMetamodel();
        IdentifierProperty identifier = model.getIdentifierProperty();
        try {
            Field field = IdentifierProperty.class.getDeclaredField("hasIdentifierMapper");
            field.setAccessible(true);
            field.set(identifier, true);
            field.setAccessible(false);
        } catch (Exception ex) {
            throw new SystemException("Attempt to fix entity meta model with hack failed, reason: " + ex.getMessage(), ex);
        }
    }
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata) Field(java.lang.reflect.Field) SystemException(com.evolveum.midpoint.util.exception.SystemException) IdentifierProperty(org.hibernate.tuple.IdentifierProperty) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 10 with ClassMetadata

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

the class JpaFlushEntityEventListener method copyState.

private boolean copyState(Object entity, Type[] types, Object[] state, SessionFactory sf) {
    // copy the entity state into the state array and return true if the state has changed
    ClassMetadata metadata = sf.getClassMetadata(entity.getClass());
    Object[] newState = metadata.getPropertyValues(entity);
    int size = newState.length;
    boolean isDirty = false;
    for (int index = 0; index < size; index++) {
        if ((state[index] == LazyPropertyInitializer.UNFETCHED_PROPERTY && newState[index] != LazyPropertyInitializer.UNFETCHED_PROPERTY) || (state[index] != newState[index] && !types[index].isEqual(state[index], newState[index]))) {
            isDirty = true;
            state[index] = newState[index];
        }
    }
    return isDirty;
}
Also used : ClassMetadata(org.hibernate.metadata.ClassMetadata)

Aggregations

ClassMetadata (org.hibernate.metadata.ClassMetadata)17 Type (org.hibernate.type.Type)7 ComponentType (org.hibernate.type.ComponentType)4 MasterDataEntity (org.mifos.application.master.business.MasterDataEntity)4 AbstractBusinessObject (org.mifos.framework.business.AbstractBusinessObject)4 Test (org.junit.Test)3 MeetingBO (org.mifos.application.meeting.business.MeetingBO)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 AbstractEntityPersister (org.hibernate.persister.entity.AbstractEntityPersister)2 CollectionType (org.hibernate.type.CollectionType)2 Money (org.mifos.framework.util.helpers.Money)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 ImmutableList (com.google.common.collect.ImmutableList)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1