use of org.hibernate.tuple.entity.EntityMetamodel 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.tuple.entity.EntityMetamodel in project hibernate-orm by hibernate.
the class LazyBasicFieldNotInitializedTestTask method execute.
public void execute() {
Session s = getFactory().openSession();
s.beginTransaction();
Entity entity = s.get(Entity.class, entityId);
Assert.assertFalse(Hibernate.isPropertyInitialized(entity, "description"));
final EntityMetamodel entityMetamodel = ((SessionFactoryImplementor) getFactory()).getEntityPersister(Entity.class.getName()).getEntityMetamodel();
final boolean[] propertyLaziness = entityMetamodel.getPropertyLaziness();
assertEquals(1, propertyLaziness.length);
assertTrue(propertyLaziness[0]);
// Make sure NonIdentifierAttribute#isLazy is consistent (HHH-10551)
final NonIdentifierAttribute[] properties = entityMetamodel.getProperties();
assertEquals(1, properties.length);
assertTrue(properties[0].isLazy());
s.getTransaction().commit();
s.close();
}
use of org.hibernate.tuple.entity.EntityMetamodel in project hibernate-orm by hibernate.
the class NullableNaturalIdTest method testNaturalIdNullability.
@Test
@TestForIssue(jiraKey = "HHH-10360")
public void testNaturalIdNullability() {
// A, B, C, and D are mapped using annotations;
// none are mapped to be non-nullable, so all are nullable by annotations-specific default,
// except primitives
EntityPersister persister = sessionFactory().getEntityPersister(A.class.getName());
EntityMetamodel entityMetamodel = persister.getEntityMetamodel();
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("assC")]);
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("myname")]);
persister = sessionFactory().getEntityPersister(B.class.getName());
entityMetamodel = persister.getEntityMetamodel();
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("assA")]);
// naturalid is a primitive, so it is non-nullable
assertFalse(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("naturalid")]);
persister = sessionFactory().getEntityPersister(C.class.getName());
entityMetamodel = persister.getEntityMetamodel();
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("name")]);
persister = sessionFactory().getEntityPersister(D.class.getName());
entityMetamodel = persister.getEntityMetamodel();
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("name")]);
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("associatedC")]);
// User is mapped using hbm.xml; properties are explicitly mapped to be nullable
persister = sessionFactory().getEntityPersister(User.class.getName());
entityMetamodel = persister.getEntityMetamodel();
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("name")]);
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("org")]);
// intVal is a primitive; hbm.xml apparently allows primitive to be nullable
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("intVal")]);
}
use of org.hibernate.tuple.entity.EntityMetamodel in project hibernate-orm by hibernate.
the class ImmutableEntityNaturalIdTest method testNaturalIdNullability.
@Test
@TestForIssue(jiraKey = "HHH-10360")
public void testNaturalIdNullability() {
final EntityPersister persister = sessionFactory().getEntityPersister(Child.class.getName());
// nullability is not specified for either properties making up
// the natural ID, so they should be non-nullable by hbm-specific default
final EntityMetamodel entityMetamodel = persister.getEntityMetamodel();
assertFalse(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("parent")]);
assertFalse(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("name")]);
}
use of org.hibernate.tuple.entity.EntityMetamodel in project hibernate-orm by hibernate.
the class ImmutableEntityNaturalIdTest method testNaturalIdNullability.
@Test
@TestForIssue(jiraKey = "HHH-10360")
public void testNaturalIdNullability() {
final EntityPersister persister = sessionFactory().getEntityPersister(Building.class.getName());
final EntityMetamodel entityMetamodel = persister.getEntityMetamodel();
// nullability is not specified, so they should be nullable by annotations-specific default
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("address")]);
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("city")]);
assertTrue(persister.getPropertyNullability()[entityMetamodel.getPropertyIndex("state")]);
}
Aggregations