use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.
the class ImplicitMappedByTest method initData.
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
OneToManyOwned owned = new OneToManyOwned("data", null);
Set<ManyToOneOwning> referencing = new HashSet<ManyToOneOwning>();
ManyToOneOwning owning1 = new ManyToOneOwning("data1", owned);
referencing.add(owning1);
ManyToOneOwning owning2 = new ManyToOneOwning("data2", owned);
referencing.add(owning2);
owned.setReferencing(referencing);
// Revision 1
em.getTransaction().begin();
em.persist(owned);
em.persist(owning1);
em.persist(owning2);
em.getTransaction().commit();
ownedId = owned.getId();
owning1Id = owning1.getId();
owning2Id = owning2.getId();
// Revision 2
em.getTransaction().begin();
owning1 = em.find(ManyToOneOwning.class, owning1.getId());
em.remove(owning1);
em.getTransaction().commit();
// Revision 3
em.getTransaction().begin();
owning2 = em.find(ManyToOneOwning.class, owning2.getId());
owning2.setData("data2modified");
em.merge(owning2);
em.getTransaction().commit();
}
use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.
the class RelationNotAuditedTarget method initData.
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity("str1");
UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity("str2");
// No revision
em.getTransaction().begin();
em.persist(uste1);
em.persist(uste2);
em.getTransaction().commit();
// Revision 1
em.getTransaction().begin();
uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId());
uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId());
TargetNotAuditedEntity tnae1 = new TargetNotAuditedEntity(1, "tnae1", uste1);
TargetNotAuditedEntity tnae2 = new TargetNotAuditedEntity(2, "tnae2", uste2);
em.persist(tnae1);
em.persist(tnae2);
em.getTransaction().commit();
// Revision 2
em.getTransaction().begin();
tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
tnae1.setReference(uste2);
tnae2.setReference(uste1);
em.getTransaction().commit();
// Revision 3
em.getTransaction().begin();
tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
//field not changed!!!
tnae1.setReference(uste2);
tnae2.setReference(uste2);
em.getTransaction().commit();
// Revision 4
em.getTransaction().begin();
tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
tnae1.setReference(uste1);
tnae2.setReference(uste1);
em.getTransaction().commit();
//
tnae1_id = tnae1.getId();
tnae2_id = tnae2.getId();
uste1_id = uste1.getId();
uste2_id = uste2.getId();
}
use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.
the class AddDelTest method initData.
@Test
@Priority(10)
public void initData() {
// Revision 1
Session session = openSession();
session.getTransaction().begin();
GivenIdStrEntity entity = new GivenIdStrEntity(1, "data");
session.persist(entity);
session.getTransaction().commit();
// Revision 2
session.getTransaction().begin();
// Just to create second revision.
session.persist(new StrTestEntity("another data"));
entity = (GivenIdStrEntity) session.get(GivenIdStrEntity.class, 1);
// First try to remove the entity.
session.delete(entity);
// Then save it.
session.save(entity);
session.getTransaction().commit();
// Revision 3
session.getTransaction().begin();
entity = (GivenIdStrEntity) session.get(GivenIdStrEntity.class, 1);
// First try to remove the entity.
session.delete(entity);
// Then change it's state.
entity.setData("modified data");
// Finally save it.
session.save(entity);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.
the class DetachedEntityTest method initData.
@Test
@Priority(10)
public void initData() {
final Session s = openSession();
try {
// revision 1 - persist the project entity
s.getTransaction().begin();
final Project project = new Project(1, "fooName");
s.persist(project);
s.getTransaction().commit();
// detach the project entity
s.clear();
// revision 2 to 6 - update the detached project entity.
for (int i = 0; i < 5; ++i) {
s.getTransaction().begin();
project.setName("fooName" + (i + 2));
s.update(project);
s.getTransaction().commit();
s.clear();
}
} catch (Throwable t) {
if (s.getTransaction().isActive()) {
s.getTransaction().rollback();
}
throw t;
} finally {
s.close();
}
}
use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.
the class HasChangedAPITest method initData.
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
em.getTransaction().begin();
AuditedTestEntity ent1 = new AuditedTestEntity(1, "str1");
NotAuditedTestEntity ent2 = new NotAuditedTestEntity(1, "str1");
em.persist(ent1);
em.persist(ent2);
em.getTransaction().commit();
em.getTransaction().begin();
ent1 = em.find(AuditedTestEntity.class, 1);
ent2 = em.find(NotAuditedTestEntity.class, 1);
ent1.setStr1("str2");
ent2.setStr1("str2");
em.getTransaction().commit();
}
Aggregations