Search in sources :

Example 6 with SetOwnedEntity

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

the class BasicSet method testHistoryOfEdId2.

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

Example 7 with SetOwnedEntity

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

the class BasicSet method testHistoryOfEdId1.

@Test
public void testHistoryOfEdId1() {
    SetOwningEntity ing1 = getEntityManager().find(SetOwningEntity.class, ing1_id);
    SetOwningEntity ing2 = getEntityManager().find(SetOwningEntity.class, ing2_id);
    SetOwnedEntity rev1 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 1);
    SetOwnedEntity rev2 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 2);
    SetOwnedEntity rev3 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 3);
    SetOwnedEntity rev4 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 4);
    SetOwnedEntity rev5 = getAuditReader().find(SetOwnedEntity.class, ed1_id, 5);
    assert rev1.getReferencing().equals(Collections.EMPTY_SET);
    assert rev2.getReferencing().equals(TestTools.makeSet(ing1, ing2));
    assert rev3.getReferencing().equals(TestTools.makeSet(ing1, ing2));
    assert rev4.getReferencing().equals(TestTools.makeSet(ing2));
    assert rev5.getReferencing().equals(TestTools.makeSet(ing2));
}
Also used : SetOwnedEntity(org.hibernate.envers.test.entities.manytomany.SetOwnedEntity) SetOwningEntity(org.hibernate.envers.test.entities.manytomany.SetOwningEntity) Test(org.junit.Test)

Example 8 with SetOwnedEntity

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

the class BasicSet method testHistoryOfEdIng2.

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

Example 9 with SetOwnedEntity

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

the class ValidityAuditStrategyManyToManyTest method testMultipleAddAndRemove.

@Test
@Priority(5)
public void testMultipleAddAndRemove() {
    final EntityManager em = getEntityManager();
    // Revision 2: add child for first time
    em.getTransaction().begin();
    SetOwningEntity owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);
    SetOwnedEntity ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id);
    owningEntity.setReferences(new HashSet<SetOwnedEntity>());
    owningEntity.getReferences().add(ownedEntity);
    em.getTransaction().commit();
    em.clear();
    // Revision 3: remove child
    em.getTransaction().begin();
    owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);
    ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id);
    owningEntity.getReferences().remove(ownedEntity);
    em.getTransaction().commit();
    em.clear();
    // Revision 4: add child again
    em.getTransaction().begin();
    owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);
    ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id);
    owningEntity.getReferences().add(ownedEntity);
    em.getTransaction().commit();
    em.clear();
    // Revision 5: remove child again
    em.getTransaction().begin();
    owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);
    ownedEntity = getEntityManager().find(SetOwnedEntity.class, ed_id);
    owningEntity.getReferences().remove(ownedEntity);
    em.getTransaction().commit();
    em.clear();
    // now the set owning entity list should be empty again
    owningEntity = getEntityManager().find(SetOwningEntity.class, ing_id);
    assertEquals(owningEntity.getReferences().size(), 0);
}
Also used : EntityManager(javax.persistence.EntityManager) SetOwnedEntity(org.hibernate.envers.test.entities.manytomany.SetOwnedEntity) SetOwningEntity(org.hibernate.envers.test.entities.manytomany.SetOwningEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 10 with SetOwnedEntity

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

the class ValidityAuditStrategyManyToManyTest method initData.

@Test
@Priority(10)
public void initData() {
    final EntityManager em = getEntityManager();
    final SetOwningEntity setOwningEntity = new SetOwningEntity(1, "parent");
    final SetOwnedEntity setOwnedEntity = new SetOwnedEntity(2, "child");
    // Revision 1: Initial persist
    em.getTransaction().begin();
    em.persist(setOwningEntity);
    em.persist(setOwnedEntity);
    em.getTransaction().commit();
    em.clear();
    ing_id = setOwningEntity.getId();
    ed_id = setOwnedEntity.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) SetOwnedEntity(org.hibernate.envers.test.entities.manytomany.SetOwnedEntity) SetOwningEntity(org.hibernate.envers.test.entities.manytomany.SetOwningEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

SetOwnedEntity (org.hibernate.envers.test.entities.manytomany.SetOwnedEntity)16 SetOwningEntity (org.hibernate.envers.test.entities.manytomany.SetOwningEntity)15 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)4 List (java.util.List)4 EntityManager (javax.persistence.EntityManager)4 Priority (org.hibernate.envers.test.Priority)4 HashSet (java.util.HashSet)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 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 TernaryMapEntity (org.hibernate.envers.test.integration.manytomany.ternary.TernaryMapEntity)1