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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations