Search in sources :

Example 41 with StrTestEntity

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

the class BasicUniSet method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    StrTestEntity ed1 = new StrTestEntity("data_ed_1");
    StrTestEntity ed2 = new StrTestEntity("data_ed_2");
    SetUniEntity ing1 = new SetUniEntity(3, "data_ing_1");
    SetUniEntity ing2 = new SetUniEntity(4, "data_ing_2");
    // Revision 1
    em.getTransaction().begin();
    em.persist(ed1);
    em.persist(ed2);
    em.persist(ing1);
    em.persist(ing2);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ing1 = em.find(SetUniEntity.class, ing1.getId());
    ing2 = em.find(SetUniEntity.class, ing2.getId());
    ed1 = em.find(StrTestEntity.class, ed1.getId());
    ed2 = em.find(StrTestEntity.class, ed2.getId());
    ing1.setReferences(new HashSet<StrTestEntity>());
    ing1.getReferences().add(ed1);
    ing2.setReferences(new HashSet<StrTestEntity>());
    ing2.getReferences().add(ed1);
    ing2.getReferences().add(ed2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ing1 = em.find(SetUniEntity.class, ing1.getId());
    ed2 = em.find(StrTestEntity.class, ed2.getId());
    ed1 = em.find(StrTestEntity.class, ed1.getId());
    ing1.getReferences().add(ed2);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    ing1 = em.find(SetUniEntity.class, ing1.getId());
    ed2 = em.find(StrTestEntity.class, ed2.getId());
    ed1 = em.find(StrTestEntity.class, ed1.getId());
    ing1.getReferences().remove(ed1);
    em.getTransaction().commit();
    // Revision 5
    em.getTransaction().begin();
    ing1 = em.find(SetUniEntity.class, ing1.getId());
    ing1.setReferences(null);
    em.getTransaction().commit();
    //
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
    ing1_id = ing1.getId();
    ing2_id = ing2.getId();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) SetUniEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.SetUniEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 42 with StrTestEntity

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

the class BasicUniSet method testHistoryOfEdIng2.

@Test
public void testHistoryOfEdIng2() {
    StrTestEntity ed1 = getEntityManager().find(StrTestEntity.class, ed1_id);
    StrTestEntity ed2 = getEntityManager().find(StrTestEntity.class, ed2_id);
    SetUniEntity rev1 = getAuditReader().find(SetUniEntity.class, ing2_id, 1);
    SetUniEntity rev2 = getAuditReader().find(SetUniEntity.class, ing2_id, 2);
    SetUniEntity rev3 = getAuditReader().find(SetUniEntity.class, ing2_id, 3);
    SetUniEntity rev4 = getAuditReader().find(SetUniEntity.class, ing2_id, 4);
    SetUniEntity rev5 = getAuditReader().find(SetUniEntity.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 : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) SetUniEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.SetUniEntity) Test(org.junit.Test)

Example 43 with StrTestEntity

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

the class JoinTableDetachedTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1 - addition
    em.getTransaction().begin();
    JoinTableEntity collectionEntity = new JoinTableEntity("some data");
    StrTestEntity element1 = new StrTestEntity("str1");
    StrTestEntity element2 = new StrTestEntity("str2");
    collectionEntity.getReferences().add(element1);
    collectionEntity.getReferences().add(element2);
    em.persist(element1);
    em.persist(element2);
    em.persist(collectionEntity);
    em.getTransaction().commit();
    collectionEntityId = collectionEntity.getId();
    element1Id = element1.getId();
    element2Id = element2.getId();
    em.close();
    em = getEntityManager();
    // Revision 2 - simple modification
    em.getTransaction().begin();
    collectionEntity = em.find(JoinTableEntity.class, collectionEntity.getId());
    collectionEntity.setData("some other data");
    collectionEntity = em.merge(collectionEntity);
    em.getTransaction().commit();
    em.close();
    em = getEntityManager();
    // Revision 3 - remove detached object from collection
    em.getTransaction().begin();
    collectionEntity = em.find(JoinTableEntity.class, collectionEntity.getId());
    collectionEntity.getReferences().remove(element1);
    collectionEntity = em.merge(collectionEntity);
    em.getTransaction().commit();
    em.close();
    em = getEntityManager();
    // Revision 4 - replace the collection
    em.getTransaction().begin();
    collectionEntity = em.find(JoinTableEntity.class, collectionEntity.getId());
    collectionEntity.setReferences(new HashSet<StrTestEntity>());
    collectionEntity = em.merge(collectionEntity);
    em.getTransaction().commit();
    em.close();
    em = getEntityManager();
    // Revision 5 - add to collection
    em.getTransaction().begin();
    collectionEntity = em.find(JoinTableEntity.class, collectionEntity.getId());
    collectionEntity.getReferences().add(element1);
    collectionEntity = em.merge(collectionEntity);
    em.getTransaction().commit();
    em.close();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) JoinTableEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.JoinTableEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 44 with StrTestEntity

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

the class JoinTableDetachedTest method testHistoryOfCollectionEntity.

@Test
public void testHistoryOfCollectionEntity() {
    // Revision 1
    JoinTableEntity collectionEntity = new JoinTableEntity(collectionEntityId, "some data");
    StrTestEntity element1 = new StrTestEntity("str1", element1Id);
    StrTestEntity element2 = new StrTestEntity("str2", element2Id);
    collectionEntity.getReferences().add(element1);
    collectionEntity.getReferences().add(element2);
    JoinTableEntity ver1 = getAuditReader().find(JoinTableEntity.class, collectionEntityId, 1);
    Assert.assertEquals(collectionEntity, ver1);
    Assert.assertEquals(collectionEntity.getReferences(), ver1.getReferences());
    // Revision 2
    collectionEntity.setData("some other data");
    JoinTableEntity ver2 = getAuditReader().find(JoinTableEntity.class, collectionEntityId, 2);
    Assert.assertEquals(collectionEntity, ver2);
    Assert.assertEquals(collectionEntity.getReferences(), ver2.getReferences());
    // Revision 3
    collectionEntity.getReferences().remove(element1);
    JoinTableEntity ver3 = getAuditReader().find(JoinTableEntity.class, collectionEntityId, 3);
    Assert.assertEquals(collectionEntity, ver3);
    Assert.assertEquals(collectionEntity.getReferences(), ver3.getReferences());
    // Revision 4
    collectionEntity.setReferences(new HashSet<StrTestEntity>());
    JoinTableEntity ver4 = getAuditReader().find(JoinTableEntity.class, collectionEntityId, 4);
    Assert.assertEquals(collectionEntity, ver4);
    Assert.assertEquals(collectionEntity.getReferences(), ver4.getReferences());
    // Revision 5
    collectionEntity.getReferences().add(element1);
    JoinTableEntity ver5 = getAuditReader().find(JoinTableEntity.class, collectionEntityId, 5);
    Assert.assertEquals(collectionEntity, ver5);
    Assert.assertEquals(collectionEntity.getReferences(), ver5.getReferences());
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) JoinTableEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.JoinTableEntity) Test(org.junit.Test)

Example 45 with StrTestEntity

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

the class CustomComparatorEntityTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    SortedSetEntity entity1 = new SortedSetEntity(1, "sortedEntity1");
    // Revision 1
    em.getTransaction().begin();
    em.persist(entity1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    entity1 = em.find(SortedSetEntity.class, 1);
    final StrTestEntity strTestEntity1 = new StrTestEntity("abc");
    em.persist(strTestEntity1);
    id1 = strTestEntity1.getId();
    entity1.getSortedSet().add(strTestEntity1);
    entity1.getSortedMap().put(strTestEntity1, "abc");
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    entity1 = em.find(SortedSetEntity.class, 1);
    final StrTestEntity strTestEntity2 = new StrTestEntity("aaa");
    em.persist(strTestEntity2);
    id2 = strTestEntity2.getId();
    entity1.getSortedSet().add(strTestEntity2);
    entity1.getSortedMap().put(strTestEntity2, "aaa");
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    entity1 = em.find(SortedSetEntity.class, 1);
    final StrTestEntity strTestEntity3 = new StrTestEntity("aba");
    em.persist(strTestEntity3);
    id3 = strTestEntity3.getId();
    entity1.getSortedSet().add(strTestEntity3);
    entity1.getSortedMap().put(strTestEntity3, "aba");
    em.getTransaction().commit();
    // Revision 5
    em.getTransaction().begin();
    entity1 = em.find(SortedSetEntity.class, 1);
    final StrTestEntity strTestEntity4 = new StrTestEntity("aac");
    em.persist(strTestEntity4);
    id4 = strTestEntity4.getId();
    entity1.getSortedSet().add(strTestEntity4);
    entity1.getSortedMap().put(strTestEntity4, "aac");
    em.getTransaction().commit();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) SortedSetEntity(org.hibernate.envers.test.entities.manytomany.SortedSetEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)102 Test (org.junit.Test)98 EntityManager (javax.persistence.EntityManager)50 Priority (org.hibernate.envers.test.Priority)48 Session (org.hibernate.Session)8 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)8 ListRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity)4 SetRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity)4 TestForIssue (org.hibernate.testing.TestForIssue)4 ManyToOneComponent (org.hibernate.envers.test.entities.components.relations.ManyToOneComponent)3 ManyToOneComponentTestEntity (org.hibernate.envers.test.entities.components.relations.ManyToOneComponentTestEntity)3 OneToManyComponent (org.hibernate.envers.test.entities.components.relations.OneToManyComponent)3 OneToManyComponentTestEntity (org.hibernate.envers.test.entities.components.relations.OneToManyComponentTestEntity)3 SortedSetEntity (org.hibernate.envers.test.entities.manytomany.SortedSetEntity)3 ListUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.ListUniEntity)3 SetUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.SetUniEntity)3 List (java.util.List)2 RevisionType (org.hibernate.envers.RevisionType)2 JoinTableEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.JoinTableEntity)2 MapUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.MapUniEntity)2