Search in sources :

Example 1 with BiRefEdEntity

use of org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefEdEntity in project hibernate-orm by hibernate.

the class OneToOneCache method initData.

@Test
@Priority(10)
public void initData() {
    BiRefEdEntity ed1 = new BiRefEdEntity(1, "data_ed_1");
    BiRefEdEntity ed2 = new BiRefEdEntity(2, "data_ed_2");
    BiRefIngEntity ing1 = new BiRefIngEntity(3, "data_ing_1");
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    ing1.setReference(ed1);
    em.persist(ed1);
    em.persist(ed2);
    em.persist(ing1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ing1 = em.find(BiRefIngEntity.class, ing1.getId());
    ed2 = em.find(BiRefEdEntity.class, ed2.getId());
    ing1.setReference(ed2);
    em.getTransaction().commit();
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
    ing1_id = ing1.getId();
}
Also used : BiRefIngEntity(org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefIngEntity) EntityManager(javax.persistence.EntityManager) BiRefEdEntity(org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefEdEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 2 with BiRefEdEntity

use of org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefEdEntity in project hibernate-orm by hibernate.

the class HasChangedBidirectional2 method initData.

@Test
@Priority(10)
public void initData() {
    BiRefEdEntity ed1 = new BiRefEdEntity(1, "data_ed_1");
    BiRefEdEntity ed2 = new BiRefEdEntity(2, "data_ed_2");
    BiRefIngEntity ing1 = new BiRefIngEntity(3, "data_ing_1");
    BiRefIngEntity ing2 = new BiRefIngEntity(4, "data_ing_2");
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    em.persist(ed1);
    em.persist(ed2);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ed1 = em.find(BiRefEdEntity.class, ed1.getId());
    ing1.setReference(ed1);
    em.persist(ing1);
    em.persist(ing2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ed1 = em.find(BiRefEdEntity.class, ed1.getId());
    ing1 = em.find(BiRefIngEntity.class, ing1.getId());
    ing2 = em.find(BiRefIngEntity.class, ing2.getId());
    ing1.setReference(null);
    ing2.setReference(ed1);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    ed2 = em.find(BiRefEdEntity.class, ed2.getId());
    ing1 = em.find(BiRefIngEntity.class, ing1.getId());
    ing2 = em.find(BiRefIngEntity.class, ing2.getId());
    ing1.setReference(ed2);
    ing2.setReference(null);
    em.getTransaction().commit();
    //
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
}
Also used : BiRefIngEntity(org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefIngEntity) EntityManager(javax.persistence.EntityManager) BiRefEdEntity(org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefEdEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 3 with BiRefEdEntity

use of org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefEdEntity in project hibernate-orm by hibernate.

the class OneToOneCache method testCacheReferenceAccessAfterFindRev1.

@Test
public void testCacheReferenceAccessAfterFindRev1() {
    BiRefEdEntity ed1_rev1 = getAuditReader().find(BiRefEdEntity.class, ed1_id, 1);
    BiRefIngEntity ing1_rev1 = getAuditReader().find(BiRefIngEntity.class, ing1_id, 1);
    assert ing1_rev1.getReference() == ed1_rev1;
}
Also used : BiRefIngEntity(org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefIngEntity) BiRefEdEntity(org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefEdEntity) Test(org.junit.Test)

Example 4 with BiRefEdEntity

use of org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefEdEntity in project hibernate-orm by hibernate.

the class OneToOneCache method testCacheReferenceAccessAfterFindRev2.

@Test
public void testCacheReferenceAccessAfterFindRev2() {
    BiRefEdEntity ed2_rev2 = getAuditReader().find(BiRefEdEntity.class, ed2_id, 2);
    BiRefIngEntity ing1_rev2 = getAuditReader().find(BiRefIngEntity.class, ing1_id, 2);
    assert ing1_rev2.getReference() == ed2_rev2;
}
Also used : BiRefIngEntity(org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefIngEntity) BiRefEdEntity(org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefEdEntity) Test(org.junit.Test)

Aggregations

BiRefEdEntity (org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefEdEntity)4 BiRefIngEntity (org.hibernate.envers.test.integration.onetoone.bidirectional.BiRefIngEntity)4 Test (org.junit.Test)4 EntityManager (javax.persistence.EntityManager)2 Priority (org.hibernate.envers.test.Priority)2