Search in sources :

Example 6 with ListOwnedEntity

use of org.hibernate.envers.test.entities.manytomany.ListOwnedEntity in project hibernate-orm by hibernate.

the class BasicList method testHistoryOfEdIng1.

@Test
public void testHistoryOfEdIng1() {
    ListOwnedEntity ed1 = getEntityManager().find(ListOwnedEntity.class, ed1_id);
    ListOwnedEntity ed2 = getEntityManager().find(ListOwnedEntity.class, ed2_id);
    ListOwningEntity rev1 = getAuditReader().find(ListOwningEntity.class, ing1_id, 1);
    ListOwningEntity rev2 = getAuditReader().find(ListOwningEntity.class, ing1_id, 2);
    ListOwningEntity rev3 = getAuditReader().find(ListOwningEntity.class, ing1_id, 3);
    ListOwningEntity rev4 = getAuditReader().find(ListOwningEntity.class, ing1_id, 4);
    ListOwningEntity rev5 = getAuditReader().find(ListOwningEntity.class, ing1_id, 5);
    assert rev1.getReferences().equals(Collections.EMPTY_LIST);
    assert TestTools.checkCollection(rev2.getReferences(), ed1);
    assert TestTools.checkCollection(rev3.getReferences(), ed1, ed2);
    assert TestTools.checkCollection(rev4.getReferences(), ed2);
    assert rev5.getReferences().equals(Collections.EMPTY_LIST);
}
Also used : ListOwnedEntity(org.hibernate.envers.test.entities.manytomany.ListOwnedEntity) ListOwningEntity(org.hibernate.envers.test.entities.manytomany.ListOwningEntity) Test(org.junit.Test)

Example 7 with ListOwnedEntity

use of org.hibernate.envers.test.entities.manytomany.ListOwnedEntity in project hibernate-orm by hibernate.

the class BasicList method testHistoryOfEdIng2.

@Test
public void testHistoryOfEdIng2() {
    ListOwnedEntity ed1 = getEntityManager().find(ListOwnedEntity.class, ed1_id);
    ListOwnedEntity ed2 = getEntityManager().find(ListOwnedEntity.class, ed2_id);
    ListOwningEntity rev1 = getAuditReader().find(ListOwningEntity.class, ing2_id, 1);
    ListOwningEntity rev2 = getAuditReader().find(ListOwningEntity.class, ing2_id, 2);
    ListOwningEntity rev3 = getAuditReader().find(ListOwningEntity.class, ing2_id, 3);
    ListOwningEntity rev4 = getAuditReader().find(ListOwningEntity.class, ing2_id, 4);
    ListOwningEntity rev5 = getAuditReader().find(ListOwningEntity.class, ing2_id, 5);
    assert rev1.getReferences().equals(Collections.EMPTY_LIST);
    assert TestTools.checkCollection(rev2.getReferences(), ed1, ed2);
    assert TestTools.checkCollection(rev3.getReferences(), ed1, ed2);
    assert TestTools.checkCollection(rev4.getReferences(), ed1, ed2);
    assert TestTools.checkCollection(rev5.getReferences(), ed1, ed2);
}
Also used : ListOwnedEntity(org.hibernate.envers.test.entities.manytomany.ListOwnedEntity) ListOwningEntity(org.hibernate.envers.test.entities.manytomany.ListOwningEntity) Test(org.junit.Test)

Example 8 with ListOwnedEntity

use of org.hibernate.envers.test.entities.manytomany.ListOwnedEntity in project hibernate-orm by hibernate.

the class AbstractRevisionEntityRemovalTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1 - simple entity
    em.getTransaction().begin();
    em.persist(new StrTestEntity("data"));
    em.getTransaction().commit();
    // Revision 2 - many-to-many relation
    em.getTransaction().begin();
    ListOwnedEntity owned = new ListOwnedEntity(1, "data");
    ListOwningEntity owning = new ListOwningEntity(1, "data");
    owned.setReferencing(new ArrayList<ListOwningEntity>());
    owning.setReferences(new ArrayList<ListOwnedEntity>());
    owned.getReferencing().add(owning);
    owning.getReferences().add(owned);
    em.persist(owned);
    em.persist(owning);
    em.getTransaction().commit();
    em.getTransaction().begin();
    Assert.assertEquals(1, countRecords(em, "STR_TEST_AUD"));
    Assert.assertEquals(1, countRecords(em, "ListOwned_AUD"));
    Assert.assertEquals(1, countRecords(em, "ListOwning_AUD"));
    Assert.assertEquals(1, countRecords(em, "ListOwning_ListOwned_AUD"));
    em.getTransaction().commit();
    em.close();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) ListOwnedEntity(org.hibernate.envers.test.entities.manytomany.ListOwnedEntity) ListOwningEntity(org.hibernate.envers.test.entities.manytomany.ListOwningEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

ListOwnedEntity (org.hibernate.envers.test.entities.manytomany.ListOwnedEntity)8 ListOwningEntity (org.hibernate.envers.test.entities.manytomany.ListOwningEntity)8 Test (org.junit.Test)8 EntityManager (javax.persistence.EntityManager)3 Priority (org.hibernate.envers.test.Priority)3 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 IntTestPrivSeqEntity (org.hibernate.envers.test.entities.IntTestPrivSeqEntity)1 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)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 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 SetRefEdEntity (org.hibernate.envers.test.entities.onetomany.SetRefEdEntity)1 SetRefIngEntity (org.hibernate.envers.test.entities.onetomany.SetRefIngEntity)1