HHH-5750 - Proxied objects lose the temporary session used to initialize them

This commit is contained in:
Erik-Berndt Scheper 2010-12-22 11:37:07 +01:00
parent 1dc7317694
commit f125f06c45
2 changed files with 76 additions and 1 deletions

View File

@ -82,7 +82,6 @@ public class Tools {
proxy.getHibernateLazyInitializer().getEntityName(),
proxy.getHibernateLazyInitializer().getIdentifier()
);
proxy.getHibernateLazyInitializer().setImplementation( target );
return target;
}
finally {

View File

@ -0,0 +1,76 @@
package org.hibernate.envers.test.integration.proxy;
import javax.persistence.EntityManager;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.entities.onetomany.ListRefEdEntity;
import org.hibernate.envers.test.entities.onetomany.ListRefIngEntity;
import org.hibernate.proxy.HibernateProxy;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* Test case for HHH-5750: Proxied objects lose the temporary session used to
* initialize them.
*
* @author Erik-Berndt Scheper
*
*/
public class AuditedCollectionProxyTest extends AbstractEntityTest {
Integer id_ListRefEdEntity1;
public void configure(Ejb3Configuration cfg) {
cfg.addAnnotatedClass(ListRefEdEntity.class);
cfg.addAnnotatedClass(ListRefIngEntity.class);
}
@BeforeClass(dependsOnMethods = "init")
public void initData() {
EntityManager em = getEntityManager();
ListRefEdEntity listReferencedEntity1 = new ListRefEdEntity(
Integer.valueOf(1), "str1");
ListRefIngEntity refingEntity1 = new ListRefIngEntity(
Integer.valueOf(1), "refing1", listReferencedEntity1);
// Revision 1
em.getTransaction().begin();
em.persist(listReferencedEntity1);
em.persist(refingEntity1);
em.getTransaction().commit();
id_ListRefEdEntity1 = listReferencedEntity1.getId();
// Revision 2
ListRefIngEntity refingEntity2 = new ListRefIngEntity(
Integer.valueOf(2), "refing2", listReferencedEntity1);
em.getTransaction().begin();
em.persist(refingEntity2);
em.getTransaction().commit();
}
@Test
public void testProxyIdentifier() {
EntityManager em = getEntityManager();
ListRefEdEntity listReferencedEntity1 = em.getReference(
ListRefEdEntity.class, id_ListRefEdEntity1);
assert listReferencedEntity1 instanceof HibernateProxy;
// Revision 3
ListRefIngEntity refingEntity3 = new ListRefIngEntity(
Integer.valueOf(3), "refing3", listReferencedEntity1);
em.getTransaction().begin();
em.persist(refingEntity3);
em.getTransaction().commit();
listReferencedEntity1.getReffering().size();
}
}