Search in sources :

Example 31 with Priority

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

the class ManualFlush method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrTestEntity fe = new StrTestEntity("x");
    em.persist(fe);
    em.flush();
    em.getTransaction().commit();
    // No revision - we change the data, but do not flush the session
    em.getTransaction().begin();
    fe = em.find(StrTestEntity.class, fe.getId());
    fe.setStr("y");
    em.getTransaction().commit();
    // Revision 2 - only the first change should be saved
    em.getTransaction().begin();
    fe = em.find(StrTestEntity.class, fe.getId());
    fe.setStr("z");
    em.flush();
    fe = em.find(StrTestEntity.class, fe.getId());
    fe.setStr("z2");
    em.getTransaction().commit();
    //
    id = fe.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 32 with Priority

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

the class Serializables method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    SerializableTestEntity ste = new SerializableTestEntity(new SerObject("d1"));
    em.persist(ste);
    id1 = ste.getId();
    em.getTransaction().commit();
    em.getTransaction().begin();
    ste = em.find(SerializableTestEntity.class, id1);
    ste.setObj(new SerObject("d2"));
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 33 with Priority

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

the class HasChangedCompositeCustom method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    CompositeCustomTypeEntity ccte = new CompositeCustomTypeEntity();
    // Revision 1 (persisting 1 entity)
    em.getTransaction().begin();
    ccte.setComponent(new Component("a", 1));
    em.persist(ccte);
    em.getTransaction().commit();
    // Revision 2 (changing the component)
    em.getTransaction().begin();
    ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
    ccte.getComponent().setProp1("b");
    em.getTransaction().commit();
    // Revision 3 (replacing the component)
    em.getTransaction().begin();
    ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
    ccte.setComponent(new Component("c", 3));
    em.getTransaction().commit();
    //
    ccte_id = ccte.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) CompositeCustomTypeEntity(org.hibernate.envers.test.entities.customtype.CompositeCustomTypeEntity) Component(org.hibernate.envers.test.entities.customtype.Component) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 34 with Priority

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

the class HasChangedDetachedMultipleCollection method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1 - addition.
    em.getTransaction().begin();
    MultipleCollectionEntity mce1 = new MultipleCollectionEntity();
    mce1.setText("MultipleCollectionEntity-1-1");
    // Persisting entity with empty collections.
    em.persist(mce1);
    em.getTransaction().commit();
    mce1Id = mce1.getId();
    // Revision 2 - update.
    em.getTransaction().begin();
    mce1 = em.find(MultipleCollectionEntity.class, mce1.getId());
    MultipleCollectionRefEntity1 mcre1 = new MultipleCollectionRefEntity1();
    mcre1.setText("MultipleCollectionRefEntity1-1-1");
    mcre1.setMultipleCollectionEntity(mce1);
    mce1.addRefEntity1(mcre1);
    em.persist(mcre1);
    mce1 = em.merge(mce1);
    em.getTransaction().commit();
    mcre1Id = mcre1.getId();
    // No changes.
    em.getTransaction().begin();
    mce1 = em.find(MultipleCollectionEntity.class, mce1.getId());
    mce1 = em.merge(mce1);
    em.getTransaction().commit();
    em.close();
    em = getEntityManager();
    // Revision 3 - updating detached collection.
    em.getTransaction().begin();
    mce1.removeRefEntity1(mcre1);
    mce1 = em.merge(mce1);
    em.getTransaction().commit();
    em.close();
    em = getEntityManager();
    // Revision 4 - updating detached entity, no changes to collection attributes.
    em.getTransaction().begin();
    mce1.setRefEntities1(new ArrayList<MultipleCollectionRefEntity1>());
    mce1.setRefEntities2(new ArrayList<MultipleCollectionRefEntity2>());
    mce1.setText("MultipleCollectionEntity-1-2");
    mce1 = em.merge(mce1);
    em.getTransaction().commit();
    em.close();
    em = getEntityManager();
    // No changes to detached entity (collections were empty beforeQuery).
    em.getTransaction().begin();
    mce1.setRefEntities1(new ArrayList<MultipleCollectionRefEntity1>());
    mce1.setRefEntities2(new ArrayList<MultipleCollectionRefEntity2>());
    mce1 = em.merge(mce1);
    em.getTransaction().commit();
    // Revision 5 - addition.
    em.getTransaction().begin();
    MultipleCollectionEntity mce2 = new MultipleCollectionEntity();
    mce2.setText("MultipleCollectionEntity-2-1");
    MultipleCollectionRefEntity2 mcre2 = new MultipleCollectionRefEntity2();
    mcre2.setText("MultipleCollectionRefEntity2-1-1");
    mcre2.setMultipleCollectionEntity(mce2);
    mce2.addRefEntity2(mcre2);
    // Cascade persisting related entity.
    em.persist(mce2);
    em.getTransaction().commit();
    mce2Id = mce2.getId();
    mcre2Id = mcre2.getId();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) MultipleCollectionEntity(org.hibernate.envers.test.entities.collection.MultipleCollectionEntity) MultipleCollectionRefEntity1(org.hibernate.envers.test.entities.collection.MultipleCollectionRefEntity1) MultipleCollectionRefEntity2(org.hibernate.envers.test.entities.collection.MultipleCollectionRefEntity2) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 35 with Priority

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

the class HasChangedDoubleJoinColumnBidirectionalList method createData.

@Test
@Priority(10)
public void createData() {
    EntityManager em = getEntityManager();
    DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_1 = new DoubleListJoinColumnBidirectionalRefEdEntity1("ed1_1", null);
    DoubleListJoinColumnBidirectionalRefEdEntity1 ed1_2 = new DoubleListJoinColumnBidirectionalRefEdEntity1("ed1_2", null);
    DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_1 = new DoubleListJoinColumnBidirectionalRefEdEntity2("ed2_1", null);
    DoubleListJoinColumnBidirectionalRefEdEntity2 ed2_2 = new DoubleListJoinColumnBidirectionalRefEdEntity2("ed2_2", null);
    DoubleListJoinColumnBidirectionalRefIngEntity ing1 = new DoubleListJoinColumnBidirectionalRefIngEntity("coll1");
    DoubleListJoinColumnBidirectionalRefIngEntity ing2 = new DoubleListJoinColumnBidirectionalRefIngEntity("coll2");
    // Revision 1 (ing1: ed1_1, ed2_1, ing2: ed1_2, ed2_2)
    em.getTransaction().begin();
    ing1.getReferences1().add(ed1_1);
    ing1.getReferences2().add(ed2_1);
    ing2.getReferences1().add(ed1_2);
    ing2.getReferences2().add(ed2_2);
    em.persist(ed1_1);
    em.persist(ed1_2);
    em.persist(ed2_1);
    em.persist(ed2_2);
    em.persist(ing1);
    em.persist(ing2);
    em.getTransaction().commit();
    // Revision 2 (ing1: ed1_1, ed1_2, ed2_1, ed2_2)
    em.getTransaction().begin();
    ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId());
    ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId());
    ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId());
    ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId());
    ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId());
    ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId());
    ing2.getReferences1().clear();
    ing2.getReferences2().clear();
    ing1.getReferences1().add(ed1_2);
    ing1.getReferences2().add(ed2_2);
    em.getTransaction().commit();
    em.clear();
    // Revision 3 (ing1: ed1_1, ed1_2, ed2_1, ed2_2)
    em.getTransaction().begin();
    ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId());
    ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId());
    ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId());
    ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId());
    ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId());
    ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId());
    ed1_1.setData("ed1_1 bis");
    ed2_2.setData("ed2_2 bis");
    em.getTransaction().commit();
    em.clear();
    // Revision 4 (ing1: ed2_2, ing2: ed2_1, ed1_1, ed1_2)
    em.getTransaction().begin();
    ing1 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing1.getId());
    ing2 = em.find(DoubleListJoinColumnBidirectionalRefIngEntity.class, ing2.getId());
    ed1_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_1.getId());
    ed1_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity1.class, ed1_2.getId());
    ed2_1 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_1.getId());
    ed2_2 = em.find(DoubleListJoinColumnBidirectionalRefEdEntity2.class, ed2_2.getId());
    ing1.getReferences1().clear();
    ing2.getReferences1().add(ed1_1);
    ing2.getReferences1().add(ed1_2);
    ing1.getReferences2().remove(ed2_1);
    ing2.getReferences2().add(ed2_1);
    em.getTransaction().commit();
    em.clear();
    //
    ing1_id = ing1.getId();
    ing2_id = ing2.getId();
    ed1_1_id = ed1_1.getId();
    ed1_2_id = ed1_2.getId();
    ed2_1_id = ed2_1.getId();
    ed2_2_id = ed2_2.getId();
}
Also used : DoubleListJoinColumnBidirectionalRefEdEntity2(org.hibernate.envers.test.entities.onetomany.detached.DoubleListJoinColumnBidirectionalRefEdEntity2) DoubleListJoinColumnBidirectionalRefEdEntity1(org.hibernate.envers.test.entities.onetomany.detached.DoubleListJoinColumnBidirectionalRefEdEntity1) EntityManager(javax.persistence.EntityManager) DoubleListJoinColumnBidirectionalRefIngEntity(org.hibernate.envers.test.entities.onetomany.detached.DoubleListJoinColumnBidirectionalRefIngEntity) 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