Search in sources :

Example 91 with Priority

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

the class AggregateQuery method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1
    em.getTransaction().begin();
    IntTestEntity ite1 = new IntTestEntity(2);
    IntTestEntity ite2 = new IntTestEntity(10);
    em.persist(ite1);
    em.persist(ite2);
    Integer id1 = ite1.getId();
    Integer id2 = ite2.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    IntTestEntity ite3 = new IntTestEntity(8);
    UnusualIdNamingEntity uine1 = new UnusualIdNamingEntity("id1", "data1");
    em.persist(uine1);
    em.persist(ite3);
    ite1 = em.find(IntTestEntity.class, id1);
    ite1.setNumber(0);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ite2 = em.find(IntTestEntity.class, id2);
    ite2.setNumber(52);
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) UnusualIdNamingEntity(org.hibernate.envers.test.entities.ids.UnusualIdNamingEntity) IntTestEntity(org.hibernate.envers.test.entities.IntTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 92 with Priority

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

the class MapsIdTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1
    em.getTransaction().begin();
    Person personA = new Person("Peter");
    Person personB = new Person("Mary");
    em.persist(personA);
    em.persist(personB);
    Constant cons = new Constant("USD", "US Dollar");
    em.persist(cons);
    PersonTuple tuple1 = new PersonTuple(true, personA, personB, cons);
    em.persist(tuple1);
    em.getTransaction().commit();
    tuple1Ver1 = new PersonTuple(tuple1.isHelloWorld(), tuple1.getPersonA(), tuple1.getPersonB(), tuple1.getConstant());
    // Revision 2
    em.getTransaction().begin();
    cons = em.find(Constant.class, cons.getId());
    Person personC1 = new Person("Lukasz");
    em.persist(personC1);
    PersonTuple tuple2 = new PersonTuple(true, personA, personC1, cons);
    em.persist(tuple2);
    em.getTransaction().commit();
    tuple2Ver1 = new PersonTuple(tuple2.isHelloWorld(), tuple2.getPersonA(), tuple2.getPersonB(), tuple2.getConstant());
    personCVer1 = new Person(personC1.getId(), personC1.getName());
    personCVer1.getPersonBTuples().add(tuple2Ver1);
    // Revision 3
    em.getTransaction().begin();
    tuple2 = em.find(PersonTuple.class, tuple2.getPersonTupleId());
    tuple2.setHelloWorld(false);
    em.merge(tuple2);
    em.getTransaction().commit();
    tuple2Ver2 = new PersonTuple(tuple2.isHelloWorld(), tuple2.getPersonA(), tuple2.getPersonB(), tuple2.getConstant());
    // Revision 4
    em.getTransaction().begin();
    Person personC2 = em.find(Person.class, personC1.getId());
    personC2.setName("Robert");
    em.merge(personC2);
    em.getTransaction().commit();
    personCVer2 = new Person(personC2.getId(), personC2.getName());
    personCVer2.getPersonBTuples().add(tuple2Ver1);
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 93 with Priority

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

the class HierarchyTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1
    em.getTransaction().begin();
    Node parent = new Node("parent", (Node) null);
    Node child1 = new Node("child1", parent);
    Node child2 = new Node("child2", parent);
    parent.getChildren().add(child1);
    parent.getChildren().add(child2);
    em.persist(parent);
    em.persist(child1);
    em.persist(child2);
    em.getTransaction().commit();
    parentId = parent.getId();
    child1Id = child1.getId();
    child2Id = child2.getId();
    // Revision 2
    em.getTransaction().begin();
    parent = em.find(Node.class, parent.getId());
    parent.getChildren().get(0).setData("child1 modified");
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    child2 = em.find(Node.class, child2.getId());
    em.remove(child2);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 94 with Priority

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

the class Bidirectional method initData.

@Test
@Priority(10)
public void initData() {
    BiRefEdEntity ed1 = new BiRefEdEntity(1, "data_ed_1");
    BiRefEdEntity ed2 = new BiRefEdEntity(2, "data_ed_2");
    BiRefIngEntity ing1 = new BiRefIngEntity(3, "data_ing_1");
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    ing1.setReference(ed1);
    em.persist(ed1);
    em.persist(ed2);
    em.persist(ing1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ing1 = em.find(BiRefIngEntity.class, ing1.getId());
    ed2 = em.find(BiRefEdEntity.class, ed2.getId());
    ing1.setReference(ed2);
    em.getTransaction().commit();
    //
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
    ing1_id = ing1.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 95 with Priority

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

the class BidirectionalEagerHbmTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1
    em.getTransaction().begin();
    BidirectionalEagerHbmRefEdPK ed1 = new BidirectionalEagerHbmRefEdPK("data_ed_1");
    BidirectionalEagerHbmRefIngPK ing1 = new BidirectionalEagerHbmRefIngPK("data_ing_1");
    ing1.setReference(ed1);
    em.persist(ed1);
    em.persist(ing1);
    em.getTransaction().commit();
    refIngId1 = ing1.getId();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) BidirectionalEagerHbmRefEdPK(org.hibernate.envers.test.entities.onetoone.BidirectionalEagerHbmRefEdPK) BidirectionalEagerHbmRefIngPK(org.hibernate.envers.test.entities.onetoone.BidirectionalEagerHbmRefIngPK) 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