Search in sources :

Example 16 with SetRefEdEntity

use of org.hibernate.envers.test.entities.onetomany.SetRefEdEntity in project hibernate-orm by hibernate.

the class RemovedObjectQueryTest method testReferringOneToManyDifferentRevisions.

@Test
public void testReferringOneToManyDifferentRevisions() {
    List queryResult = getAuditReader().createQuery().forRevisionsOfEntity(SetRefEdEntity.class, false, true).add(AuditEntity.id().eq(3)).add(AuditEntity.revisionType().eq(RevisionType.DEL)).getResultList();
    Object[] objArray = (Object[]) queryResult.get(0);
    Assert.assertEquals(5, getRevisionNumber(objArray[1]));
    SetRefEdEntity refEdEntity = (SetRefEdEntity) objArray[0];
    Assert.assertEquals("Demo Data 2", refEdEntity.getData());
    Hibernate.initialize(refEdEntity.getReffering());
    Assert.assertTrue(refEdEntity.getReffering().isEmpty());
    // After commit in revision four, child entity has been removed.
    queryResult = getAuditReader().createQuery().forRevisionsOfEntity(SetRefEdEntity.class, false, true).add(AuditEntity.id().eq(3)).add(AuditEntity.revisionNumber().eq(4)).getResultList();
    objArray = (Object[]) queryResult.get(0);
    refEdEntity = (SetRefEdEntity) objArray[0];
    Assert.assertEquals("Demo Data 2", refEdEntity.getData());
    Hibernate.initialize(refEdEntity.getReffering());
    Assert.assertTrue(refEdEntity.getReffering().isEmpty());
}
Also used : SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 17 with SetRefEdEntity

use of org.hibernate.envers.test.entities.onetomany.SetRefEdEntity in project hibernate-orm by hibernate.

the class BasicSet method testHistoryOfEdId2.

@Test
public void testHistoryOfEdId2() {
    SetRefIngEntity ing1 = getEntityManager().find(SetRefIngEntity.class, ing1_id);
    SetRefIngEntity ing2 = getEntityManager().find(SetRefIngEntity.class, ing2_id);
    SetRefEdEntity rev1 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 1);
    SetRefEdEntity rev2 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 2);
    SetRefEdEntity rev3 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 3);
    SetRefEdEntity rev4 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 4);
    assert rev1.getReffering().equals(Collections.EMPTY_SET);
    assert rev2.getReffering().equals(Collections.EMPTY_SET);
    assert rev3.getReffering().equals(TestTools.makeSet(ing1));
    assert rev4.getReffering().equals(TestTools.makeSet(ing1, ing2));
}
Also used : SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) Test(org.junit.Test)

Example 18 with SetRefEdEntity

use of org.hibernate.envers.test.entities.onetomany.SetRefEdEntity in project hibernate-orm by hibernate.

the class BasicSet method initData.

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

Example 19 with SetRefEdEntity

use of org.hibernate.envers.test.entities.onetomany.SetRefEdEntity in project hibernate-orm by hibernate.

the class BasicSet method testHistoryOfEdIng1.

@Test
public void testHistoryOfEdIng1() {
    SetRefEdEntity ed1 = getEntityManager().find(SetRefEdEntity.class, ed1_id);
    SetRefEdEntity ed2 = getEntityManager().find(SetRefEdEntity.class, ed2_id);
    SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 1);
    SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 2);
    SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 3);
    SetRefIngEntity rev4 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 4);
    assert rev1 == null;
    assert rev2.getReference().equals(ed1);
    assert rev3.getReference().equals(ed2);
    assert rev4.getReference().equals(ed2);
}
Also used : SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) Test(org.junit.Test)

Example 20 with SetRefEdEntity

use of org.hibernate.envers.test.entities.onetomany.SetRefEdEntity in project hibernate-orm by hibernate.

the class BasicSetWithNullsDelete method testHistoryOfEdIng4.

@Test
public void testHistoryOfEdIng4() {
    SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1");
    SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing4_id, 1);
    SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing4_id, 2);
    SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing4_id, 3);
    SetRefIngEntity rev4 = getAuditReader().find(SetRefIngEntity.class, ing4_id, 4);
    SetRefIngEntity rev5 = getAuditReader().find(SetRefIngEntity.class, ing4_id, 5);
    assert rev1.getReference().equals(ed1);
    assert rev2.getReference().equals(ed1);
    assert rev3.getReference().equals(ed1);
    assert rev4.getReference().equals(ed1);
    assert rev5.getReference() == null;
}
Also used : SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) Test(org.junit.Test)

Aggregations

SetRefEdEntity (org.hibernate.envers.test.entities.onetomany.SetRefEdEntity)21 Test (org.junit.Test)21 SetRefIngEntity (org.hibernate.envers.test.entities.onetomany.SetRefIngEntity)20 EntityManager (javax.persistence.EntityManager)6 Priority (org.hibernate.envers.test.Priority)6 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Session (org.hibernate.Session)1 IntTestPrivSeqEntity (org.hibernate.envers.test.entities.IntTestPrivSeqEntity)1 StrTestPrivSeqEntity (org.hibernate.envers.test.entities.StrTestPrivSeqEntity)1 UnversionedStrTestEntity (org.hibernate.envers.test.entities.UnversionedStrTestEntity)1 StringSetEntity (org.hibernate.envers.test.entities.collection.StringSetEntity)1 ListOwnedEntity (org.hibernate.envers.test.entities.manytomany.ListOwnedEntity)1 ListOwningEntity (org.hibernate.envers.test.entities.manytomany.ListOwningEntity)1 SetOwnedEntity (org.hibernate.envers.test.entities.manytomany.SetOwnedEntity)1 SetOwningEntity (org.hibernate.envers.test.entities.manytomany.SetOwningEntity)1 M2MIndexedListTargetNotAuditedEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.M2MIndexedListTargetNotAuditedEntity)1 CollectionRefEdEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity)1 CollectionRefIngEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity)1