Search in sources :

Example 6 with IntTestPrivSeqEntity

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

the class TernaryMapFlush method testHistoryOfMap1.

@Test
public void testHistoryOfMap1() {
    StrTestPrivSeqEntity str1 = getEntityManager().find(StrTestPrivSeqEntity.class, str1_id);
    StrTestPrivSeqEntity str2 = getEntityManager().find(StrTestPrivSeqEntity.class, str2_id);
    IntTestPrivSeqEntity int1 = getEntityManager().find(IntTestPrivSeqEntity.class, int1_id);
    IntTestPrivSeqEntity int2 = getEntityManager().find(IntTestPrivSeqEntity.class, int2_id);
    TernaryMapEntity rev1 = getAuditReader().find(TernaryMapEntity.class, map1_id, 1);
    TernaryMapEntity rev2 = getAuditReader().find(TernaryMapEntity.class, map1_id, 2);
    TernaryMapEntity rev3 = getAuditReader().find(TernaryMapEntity.class, map1_id, 3);
    assertEquals(rev1.getMap(), TestTools.makeMap(int1, str1));
    assertEquals(rev2.getMap(), TestTools.makeMap(int1, str1, int2, str2));
    assertEquals(rev3.getMap(), TestTools.makeMap(int2, str1));
}
Also used : StrTestPrivSeqEntity(org.hibernate.envers.test.entities.StrTestPrivSeqEntity) IntTestPrivSeqEntity(org.hibernate.envers.test.entities.IntTestPrivSeqEntity) Test(org.junit.Test)

Example 7 with IntTestPrivSeqEntity

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

the class TernaryMapFlush method createData.

@Test
@Priority(10)
public void createData() {
    EntityManager em = getEntityManager();
    StrTestPrivSeqEntity str1 = new StrTestPrivSeqEntity("a");
    StrTestPrivSeqEntity str2 = new StrTestPrivSeqEntity("b");
    IntTestPrivSeqEntity int1 = new IntTestPrivSeqEntity(1);
    IntTestPrivSeqEntity int2 = new IntTestPrivSeqEntity(2);
    TernaryMapEntity map1 = new TernaryMapEntity();
    // Revision 1 (int1 -> str1)
    em.getTransaction().begin();
    em.persist(str1);
    em.persist(str2);
    em.persist(int1);
    em.persist(int2);
    map1.getMap().put(int1, str1);
    em.persist(map1);
    em.getTransaction().commit();
    // Revision 2 (removing int1->str1, flushing, adding int1->str1 again and a new int2->str2 mapping to force a change)
    em.getTransaction().begin();
    map1 = em.find(TernaryMapEntity.class, map1.getId());
    str1 = em.find(StrTestPrivSeqEntity.class, str1.getId());
    int1 = em.find(IntTestPrivSeqEntity.class, int1.getId());
    map1.setMap(new HashMap<IntTestPrivSeqEntity, StrTestPrivSeqEntity>());
    em.flush();
    map1.getMap().put(int1, str1);
    map1.getMap().put(int2, str2);
    em.getTransaction().commit();
    // Revision 3 (removing int1->str1, flushing, overwriting int2->str1)
    em.getTransaction().begin();
    map1 = em.find(TernaryMapEntity.class, map1.getId());
    str1 = em.find(StrTestPrivSeqEntity.class, str1.getId());
    int1 = em.find(IntTestPrivSeqEntity.class, int1.getId());
    map1.getMap().remove(int1);
    em.flush();
    map1.getMap().put(int2, str1);
    em.getTransaction().commit();
    //
    map1_id = map1.getId();
    str1_id = str1.getId();
    str2_id = str2.getId();
    int1_id = int1.getId();
    int2_id = int2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) StrTestPrivSeqEntity(org.hibernate.envers.test.entities.StrTestPrivSeqEntity) IntTestPrivSeqEntity(org.hibernate.envers.test.entities.IntTestPrivSeqEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

IntTestPrivSeqEntity (org.hibernate.envers.test.entities.IntTestPrivSeqEntity)7 StrTestPrivSeqEntity (org.hibernate.envers.test.entities.StrTestPrivSeqEntity)7 Test (org.junit.Test)7 EntityManager (javax.persistence.EntityManager)3 Priority (org.hibernate.envers.test.Priority)3 TernaryMapEntity (org.hibernate.envers.test.integration.manytomany.ternary.TernaryMapEntity)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)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 SetRefEdEntity (org.hibernate.envers.test.entities.onetomany.SetRefEdEntity)1 SetRefIngEntity (org.hibernate.envers.test.entities.onetomany.SetRefIngEntity)1