use of org.hibernate.proxy.HibernateProxy in project hibernate-orm by hibernate.
the class EntityInstantiator method replaceNonAuditIdProxies.
@SuppressWarnings({ "unchecked" })
private void replaceNonAuditIdProxies(Map versionsEntity, Number revision) {
final Map originalId = (Map) versionsEntity.get(enversService.getAuditEntitiesConfiguration().getOriginalIdPropName());
for (Object key : originalId.keySet()) {
final Object value = originalId.get(key);
if (value instanceof HibernateProxy) {
final HibernateProxy hibernateProxy = (HibernateProxy) value;
final LazyInitializer initializer = hibernateProxy.getHibernateLazyInitializer();
final String entityName = initializer.getEntityName();
final Serializable entityId = initializer.getIdentifier();
if (enversService.getEntitiesConfigurations().isVersioned(entityName)) {
final String entityClassName = enversService.getEntitiesConfigurations().get(entityName).getEntityClassName();
final Class entityClass = ReflectionTools.loadClass(entityClassName, enversService.getClassLoaderService());
final ToOneDelegateSessionImplementor delegate = new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision, RevisionType.DEL.equals(versionsEntity.get(enversService.getAuditEntitiesConfiguration().getRevisionTypePropName())), enversService);
originalId.put(key, versionsReader.getSessionImplementor().getFactory().getMetamodel().entityPersister(entityName).createProxy(entityId, delegate));
}
}
}
}
use of org.hibernate.proxy.HibernateProxy in project hibernate-orm by hibernate.
the class AuditedCollectionProxyTest method testProxyIdentifier.
@Test
public void testProxyIdentifier() {
EntityManager em = getEntityManager();
em.getTransaction().begin();
ListRefEdEntity listReferencedEntity1 = em.getReference(ListRefEdEntity.class, id_ListRefEdEntity1);
assert listReferencedEntity1 instanceof HibernateProxy;
// Revision 3
ListRefIngEntity refingEntity3 = new ListRefIngEntity(Integer.valueOf(3), "refing3", listReferencedEntity1);
em.persist(refingEntity3);
listReferencedEntity1.getReffering().size();
em.getTransaction().commit();
}
use of org.hibernate.proxy.HibernateProxy in project hibernate-orm by hibernate.
the class ProxyIdentifier method testProxyIdentifier.
@Test
public void testProxyIdentifier() {
TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1.getId(), 1);
Assert.assertTrue(rev1.getReference() instanceof HibernateProxy);
HibernateProxy proxyCreateByEnvers = (HibernateProxy) rev1.getReference();
LazyInitializer lazyInitializer = proxyCreateByEnvers.getHibernateLazyInitializer();
Assert.assertTrue(lazyInitializer.isUninitialized());
Assert.assertNotNull(lazyInitializer.getIdentifier());
Assert.assertEquals(tnae1.getId(), lazyInitializer.getIdentifier());
Assert.assertTrue(lazyInitializer.isUninitialized());
Assert.assertEquals(uste1.getId(), rev1.getReference().getId());
Assert.assertEquals(uste1.getStr(), rev1.getReference().getStr());
Assert.assertFalse(lazyInitializer.isUninitialized());
}
use of org.hibernate.proxy.HibernateProxy in project head by mifos.
the class InterceptHelper method getClazz.
private Class getClazz(Object obj) {
try {
HibernateProxy hibernateProxy = (HibernateProxy) obj;
LazyInitializer lazyInitializer = hibernateProxy.getHibernateLazyInitializer();
return lazyInitializer.getPersistentClass();
} catch (ClassCastException e) {
return obj.getClass();
}
}
use of org.hibernate.proxy.HibernateProxy in project hibernate-orm by hibernate.
the class LazyGroupAccessTestTask method execute.
@Override
public void execute() {
Session s = getFactory().openSession();
s.beginTransaction();
Child c1 = (Child) s.createQuery("from Child c where c.name = :name").setString("name", "steve").uniqueResult();
// verify the expected initial loaded state
assertLoaded(c1, "name");
assertNotLoaded(c1, "nickName");
assertNotLoaded(c1, "parent");
assertNotLoaded(c1, "alternateParent");
// Now lets access nickName which ought to initialize nickName and parent, but not alternateParent
c1.getNickName();
assertLoaded(c1, "nickName");
assertLoaded(c1, "parent");
assertNotLoaded(c1, "alternateParent");
assertEquals("Hibernate", c1.getParent().getNombre());
assertFalse(c1.getParent() instanceof HibernateProxy);
Child c2 = (Child) s.createQuery("from Child c where c.name = :name").setString("name", "sally").uniqueResult();
// verify the expected initial loaded state
assertLoaded(c2, "name");
assertNotLoaded(c2, "nickName");
assertNotLoaded(c2, "parent");
assertNotLoaded(c2, "alternateParent");
// Now lets access alternateParent which ought to initialize alternateParent and nothing else
c2.getAlternateParent();
assertNotLoaded(c2, "nickName");
assertNotLoaded(c2, "parent");
assertLoaded(c2, "alternateParent");
assertEquals("Hibernate", c2.getAlternateParent().getNombre());
assertFalse(c2.getAlternateParent() instanceof HibernateProxy);
s.getTransaction().commit();
s.close();
}
Aggregations