Search in sources :

Example 96 with Priority

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

the class JoinColumnBidirectionalList method createData.

@Test
@Priority(10)
public void createData() {
    EntityManager em = getEntityManager();
    ListJoinColumnBidirectionalRefEdEntity ed1 = new ListJoinColumnBidirectionalRefEdEntity("ed1", null);
    ListJoinColumnBidirectionalRefEdEntity ed2 = new ListJoinColumnBidirectionalRefEdEntity("ed2", null);
    ListJoinColumnBidirectionalRefIngEntity ing1 = new ListJoinColumnBidirectionalRefIngEntity("coll1", ed1);
    ListJoinColumnBidirectionalRefIngEntity ing2 = new ListJoinColumnBidirectionalRefIngEntity("coll1", ed2);
    // Revision 1 (ing1: ed1, ing2: ed2)
    em.getTransaction().begin();
    em.persist(ed1);
    em.persist(ed2);
    em.persist(ing1);
    em.persist(ing2);
    em.getTransaction().commit();
    // Revision 2 (ing1: ed1, ed2)
    em.getTransaction().begin();
    ing1 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing1.getId());
    ing2 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing2.getId());
    ed1 = em.find(ListJoinColumnBidirectionalRefEdEntity.class, ed1.getId());
    ed2 = em.find(ListJoinColumnBidirectionalRefEdEntity.class, ed2.getId());
    ing2.getReferences().remove(ed2);
    ing1.getReferences().add(ed2);
    em.getTransaction().commit();
    em.clear();
    // No revision - no changes
    em.getTransaction().begin();
    ing1 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing1.getId());
    ing2 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing2.getId());
    ed1 = em.find(ListJoinColumnBidirectionalRefEdEntity.class, ed1.getId());
    ed2 = em.find(ListJoinColumnBidirectionalRefEdEntity.class, ed2.getId());
    ed2.setOwner(ing2);
    em.getTransaction().commit();
    em.clear();
    // Revision 3 (ing1: ed1, ed2)
    em.getTransaction().begin();
    ed1 = em.find(ListJoinColumnBidirectionalRefEdEntity.class, ed1.getId());
    ed1.setData("ed1 bis");
    // Shouldn't get written
    ed1.setOwner(ing2);
    em.getTransaction().commit();
    em.clear();
    // Revision 4 (ing2: ed1, ed2)
    em.getTransaction().begin();
    ing1 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing1.getId());
    ing2 = em.find(ListJoinColumnBidirectionalRefIngEntity.class, ing2.getId());
    ing1.getReferences().clear();
    ing2.getReferences().add(ed1);
    ing2.getReferences().add(ed2);
    em.getTransaction().commit();
    em.clear();
    //
    ing1_id = ing1.getId();
    ing2_id = ing2.getId();
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) ListJoinColumnBidirectionalRefIngEntity(org.hibernate.envers.test.entities.onetomany.detached.ListJoinColumnBidirectionalRefIngEntity) ListJoinColumnBidirectionalRefEdEntity(org.hibernate.envers.test.entities.onetomany.detached.ListJoinColumnBidirectionalRefEdEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 97 with Priority

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

the class JoinColumnBidirectionalListWithInheritance method createData.

@Test
@Priority(10)
public void createData() {
    EntityManager em = getEntityManager();
    ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed1 = new ListJoinColumnBidirectionalInheritanceRefEdChildEntity("ed1", null, "ed1 child");
    ListJoinColumnBidirectionalInheritanceRefEdParentEntity ed2 = new ListJoinColumnBidirectionalInheritanceRefEdChildEntity("ed2", null, "ed2 child");
    ListJoinColumnBidirectionalInheritanceRefIngEntity ing1 = new ListJoinColumnBidirectionalInheritanceRefIngEntity("coll1", ed1);
    ListJoinColumnBidirectionalInheritanceRefIngEntity ing2 = new ListJoinColumnBidirectionalInheritanceRefIngEntity("coll1", ed2);
    // Revision 1 (ing1: ed1, ing2: ed2)
    em.getTransaction().begin();
    em.persist(ed1);
    em.persist(ed2);
    em.persist(ing1);
    em.persist(ing2);
    em.getTransaction().commit();
    // Revision 2 (ing1: ed1, ed2)
    em.getTransaction().begin();
    ing1 = em.find(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing1.getId());
    ing2 = em.find(ListJoinColumnBidirectionalInheritanceRefIngEntity.class, ing2.getId());
    ed1 = em.find(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed1.getId());
    ed2 = em.find(ListJoinColumnBidirectionalInheritanceRefEdParentEntity.class, ed2.getId());
    ing2.getReferences().remove(ed2);
    ing1.getReferences().add(ed2);
    em.getTransaction().commit();
    em.clear();
    //
    ing1_id = ing1.getId();
    ing2_id = ing2.getId();
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
}
Also used : ListJoinColumnBidirectionalInheritanceRefIngEntity(org.hibernate.envers.test.entities.onetomany.detached.ListJoinColumnBidirectionalInheritanceRefIngEntity) EntityManager(javax.persistence.EntityManager) ListJoinColumnBidirectionalInheritanceRefEdParentEntity(org.hibernate.envers.test.entities.onetomany.detached.ListJoinColumnBidirectionalInheritanceRefEdParentEntity) ListJoinColumnBidirectionalInheritanceRefEdChildEntity(org.hibernate.envers.test.entities.onetomany.detached.ListJoinColumnBidirectionalInheritanceRefEdChildEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 98 with Priority

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

the class CustomRevEntityQuery method initData.

@Test
@Priority(10)
public void initData() throws InterruptedException {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
    StrIntTestEntity site2 = new StrIntTestEntity("b", 15);
    em.persist(site1);
    em.persist(site2);
    id1 = site1.getId();
    id2 = site2.getId();
    em.getTransaction().commit();
    Thread.sleep(100);
    timestamp = System.currentTimeMillis();
    Thread.sleep(100);
    // Revision 2
    em.getTransaction().begin();
    site1 = em.find(StrIntTestEntity.class, id1);
    site1.setStr1("c");
    em.getTransaction().commit();
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 99 with Priority

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

the class MaximalizePropertyQuery method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrIntTestEntity site1 = new StrIntTestEntity("a", 10);
    StrIntTestEntity site2 = new StrIntTestEntity("b", 15);
    StrIntTestEntity site3 = new StrIntTestEntity("c", 42);
    StrIntTestEntity site4 = new StrIntTestEntity("d", 52);
    em.persist(site1);
    em.persist(site2);
    em.persist(site3);
    em.persist(site4);
    id1 = site1.getId();
    id2 = site2.getId();
    id3 = site3.getId();
    id4 = site4.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    site1 = em.find(StrIntTestEntity.class, id1);
    site2 = em.find(StrIntTestEntity.class, id2);
    site1.setStr1("d");
    site2.setNumber(20);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    site1 = em.find(StrIntTestEntity.class, id1);
    site2 = em.find(StrIntTestEntity.class, id2);
    site1.setNumber(30);
    site2.setStr1("z");
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    site1 = em.find(StrIntTestEntity.class, id1);
    site2 = em.find(StrIntTestEntity.class, id2);
    site1.setNumber(5);
    site2.setStr1("a");
    em.getTransaction().commit();
    // Revision 5
    em.getTransaction().begin();
    site4 = em.find(StrIntTestEntity.class, id4);
    em.remove(site4);
    em.getTransaction().commit();
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 100 with Priority

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

the class InverseSideChanges method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1");
    SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1");
    // Revision 1
    em.getTransaction().begin();
    em.persist(ed1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ed1 = em.find(SetRefEdEntity.class, ed1.getId());
    em.persist(ing1);
    ed1.setReffering(new HashSet<SetRefIngEntity>());
    ed1.getReffering().add(ing1);
    em.getTransaction().commit();
    //
    ed1_id = ed1.getId();
    ing1_id = ing1.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)

Aggregations

Priority (org.hibernate.envers.test.Priority)268 Test (org.junit.Test)268 EntityManager (javax.persistence.EntityManager)249 StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)48 Session (org.hibernate.Session)16 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)12 EmbId (org.hibernate.envers.test.entities.ids.EmbId)8 UnversionedStrTestEntity (org.hibernate.envers.test.entities.UnversionedStrTestEntity)7 Component1 (org.hibernate.envers.test.entities.components.Component1)7 MulId (org.hibernate.envers.test.entities.ids.MulId)7 HashSet (java.util.HashSet)6 IntTestEntity (org.hibernate.envers.test.entities.IntTestEntity)6 SetRefEdEntity (org.hibernate.envers.test.entities.onetomany.SetRefEdEntity)6 SetRefIngEntity (org.hibernate.envers.test.entities.onetomany.SetRefIngEntity)6 Component2 (org.hibernate.envers.test.entities.components.Component2)5 ComponentTestEntity (org.hibernate.envers.test.entities.components.ComponentTestEntity)4 CollectionRefEdEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity)4 CollectionRefIngEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3