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);
}
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();
}
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();
}
}
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);
}
}
}
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;
}
Aggregations