Search in sources :

Example 61 with Priority

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

the class VersionsJoinTableNaming method initData.

@Test
@Priority(10)
public void initData() {
    VersionsJoinTableTestEntity uni1 = new VersionsJoinTableTestEntity(1, "data1");
    StrTestEntity str1 = new StrTestEntity("str1");
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    uni1.setCollection(new HashSet<StrTestEntity>());
    em.persist(uni1);
    em.persist(str1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    uni1 = em.find(VersionsJoinTableTestEntity.class, uni1.getId());
    str1 = em.find(StrTestEntity.class, str1.getId());
    uni1.getCollection().add(str1);
    em.getTransaction().commit();
    //
    uni1_id = uni1.getId();
    str1_id = str1.getId();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 62 with Priority

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

the class HasChangedOneToManyInComponent method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrTestEntity ste1 = new StrTestEntity();
    ste1.setStr("str1");
    StrTestEntity ste2 = new StrTestEntity();
    ste2.setStr("str2");
    em.persist(ste1);
    em.persist(ste2);
    em.getTransaction().commit();
    // Revision 2
    em = getEntityManager();
    em.getTransaction().begin();
    OneToManyComponentTestEntity otmcte1 = new OneToManyComponentTestEntity(new OneToManyComponent("data1"));
    otmcte1.getComp1().getEntities().add(ste1);
    em.persist(otmcte1);
    em.getTransaction().commit();
    // Revision 3
    em = getEntityManager();
    em.getTransaction().begin();
    otmcte1 = em.find(OneToManyComponentTestEntity.class, otmcte1.getId());
    otmcte1.getComp1().getEntities().add(ste2);
    em.getTransaction().commit();
    otmcte_id1 = otmcte1.getId();
}
Also used : OneToManyComponent(org.hibernate.envers.test.entities.components.relations.OneToManyComponent) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) OneToManyComponentTestEntity(org.hibernate.envers.test.entities.components.relations.OneToManyComponentTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 63 with Priority

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

the class HasChangedChildAuditing method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    id1 = 1;
    // Rev 1
    em.getTransaction().begin();
    ChildEntity ce = new ChildEntity(id1, "x", 1l);
    em.persist(ce);
    em.getTransaction().commit();
    // Rev 2
    em.getTransaction().begin();
    ce = em.find(ChildEntity.class, id1);
    ce.setData("y");
    ce.setNumVal(2l);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) ChildEntity(org.hibernate.envers.test.integration.inheritance.joined.ChildEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 64 with Priority

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

the class HasChangedComponentMapKey method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    ComponentMapKeyEntity imke = new ComponentMapKeyEntity();
    // Revision 1 (intialy 1 mapping)
    em.getTransaction().begin();
    ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2"));
    ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("x1", "y2"), new Component2("a1", "b2"));
    em.persist(cte1);
    em.persist(cte2);
    imke.getIdmap().put(cte1.getComp1(), cte1);
    em.persist(imke);
    em.getTransaction().commit();
    // Revision 2 (sse1: adding 1 mapping)
    em.getTransaction().begin();
    cte2 = em.find(ComponentTestEntity.class, cte2.getId());
    imke = em.find(ComponentMapKeyEntity.class, imke.getId());
    imke.getIdmap().put(cte2.getComp1(), cte2);
    em.getTransaction().commit();
    //
    cmke_id = imke.getId();
    cte1_id = cte1.getId();
    cte2_id = cte2.getId();
}
Also used : ComponentMapKeyEntity(org.hibernate.envers.test.integration.collection.mapkey.ComponentMapKeyEntity) EntityManager(javax.persistence.EntityManager) Component1(org.hibernate.envers.test.entities.components.Component1) Component2(org.hibernate.envers.test.entities.components.Component2) ComponentTestEntity(org.hibernate.envers.test.entities.components.ComponentTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 65 with Priority

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

the class HasChangedComponents method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    ComponentTestEntity cte1 = new ComponentTestEntity(new Component1("a", "b"), new Component2("x", "y"));
    ComponentTestEntity cte2 = new ComponentTestEntity(new Component1("a2", "b2"), new Component2("x2", "y2"));
    ComponentTestEntity cte3 = new ComponentTestEntity(new Component1("a3", "b3"), new Component2("x3", "y3"));
    ComponentTestEntity cte4 = new ComponentTestEntity(null, null);
    em.persist(cte1);
    em.persist(cte2);
    em.persist(cte3);
    em.persist(cte4);
    em.getTransaction().commit();
    // Revision 2
    em = getEntityManager();
    em.getTransaction().begin();
    cte1 = em.find(ComponentTestEntity.class, cte1.getId());
    cte2 = em.find(ComponentTestEntity.class, cte2.getId());
    cte3 = em.find(ComponentTestEntity.class, cte3.getId());
    cte4 = em.find(ComponentTestEntity.class, cte4.getId());
    cte1.setComp1(new Component1("a'", "b'"));
    cte2.getComp1().setStr1("a2'");
    cte3.getComp2().setStr6("y3'");
    cte4.setComp1(new Component1());
    cte4.getComp1().setStr1("n");
    cte4.setComp2(new Component2());
    cte4.getComp2().setStr5("m");
    em.getTransaction().commit();
    // Revision 3
    em = getEntityManager();
    em.getTransaction().begin();
    cte1 = em.find(ComponentTestEntity.class, cte1.getId());
    cte2 = em.find(ComponentTestEntity.class, cte2.getId());
    cte3 = em.find(ComponentTestEntity.class, cte3.getId());
    cte4 = em.find(ComponentTestEntity.class, cte4.getId());
    cte1.setComp2(new Component2("x'", "y'"));
    cte3.getComp1().setStr2("b3'");
    cte4.setComp1(null);
    cte4.setComp2(null);
    em.getTransaction().commit();
    // Revision 4
    em = getEntityManager();
    em.getTransaction().begin();
    cte2 = em.find(ComponentTestEntity.class, cte2.getId());
    em.remove(cte2);
    em.getTransaction().commit();
    id1 = cte1.getId();
    id2 = cte2.getId();
    id3 = cte3.getId();
    id4 = cte4.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) Component1(org.hibernate.envers.test.entities.components.Component1) Component2(org.hibernate.envers.test.entities.components.Component2) ComponentTestEntity(org.hibernate.envers.test.entities.components.ComponentTestEntity) 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