use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.
the class HasChangedAuditedManyToManyRemovalTest method initData.
@Test
@Priority(10)
public void initData() {
EntityManager entityManager = getEntityManager();
try {
// Revision 1 - insertion
Professor professor = new Professor();
Student student = new Student();
professor.getStudents().add(student);
student.getProfessors().add(professor);
entityManager.getTransaction().begin();
entityManager.persist(professor);
entityManager.persist(student);
entityManager.getTransaction().commit();
entityManager.clear();
// Revision 2 - deletion
entityManager.getTransaction().begin();
professor = entityManager.find(Professor.class, professor.getId());
student = entityManager.find(Student.class, student.getId());
entityManager.remove(professor);
entityManager.remove(student);
// the issue is student.getProfessors() throws a LazyInitializationException.
entityManager.getTransaction().commit();
} finally {
entityManager.close();
}
}
use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.
the class HasChangedAuditedManyToManyTest method initData.
@Test
@Priority(10)
public void initData() {
initializeSession();
Person pers1 = new Person("Hernan", 28);
Person pers2 = new Person("Leandro", 29);
Person pers3 = new Person("Barba", 32);
Person pers4 = new Person("Camomo", 15);
//REV 1
getSession().getTransaction().begin();
List<Person> owners = new ArrayList<Person>();
owners.add(pers1);
owners.add(pers2);
owners.add(pers3);
Car car1 = new Car(5, owners);
getSession().persist(car1);
getSession().getTransaction().commit();
id_pers1 = pers1.getId();
id_car1 = car1.getId();
id_pers2 = pers2.getId();
owners = new ArrayList<Person>();
owners.add(pers2);
owners.add(pers3);
owners.add(pers4);
Car car2 = new Car(27, owners);
//REV 2
getSession().getTransaction().begin();
Person person1 = (Person) getSession().get("Personaje", id_pers1);
person1.setName("Hernan David");
person1.setAge(40);
getSession().persist(car1);
getSession().persist(car2);
getSession().getTransaction().commit();
}
use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.
the class HasChangedIdMapKey method initData.
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
IdMapKeyEntity imke = new IdMapKeyEntity();
// Revision 1 (intialy 1 mapping)
em.getTransaction().begin();
StrTestEntity ste1 = new StrTestEntity("x");
StrTestEntity ste2 = new StrTestEntity("y");
em.persist(ste1);
em.persist(ste2);
imke.getIdmap().put(ste1.getId(), ste1);
em.persist(imke);
em.getTransaction().commit();
// Revision 2 (sse1: adding 1 mapping)
em.getTransaction().begin();
ste2 = em.find(StrTestEntity.class, ste2.getId());
imke = em.find(IdMapKeyEntity.class, imke.getId());
imke.getIdmap().put(ste2.getId(), ste2);
em.getTransaction().commit();
//
imke_id = imke.getId();
}
use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.
the class HasChangedManualFlush method initData.
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
// Revision 1
em.getTransaction().begin();
BasicTestEntity1 entity = new BasicTestEntity1("str1", 1);
em.persist(entity);
em.getTransaction().commit();
id = entity.getId();
// Revision 2 - both properties (str1 and long1) should be marked as modified.
em.getTransaction().begin();
entity = em.find(BasicTestEntity1.class, entity.getId());
entity.setStr1("str2");
entity = em.merge(entity);
em.flush();
entity.setLong1(2);
entity = em.merge(entity);
em.flush();
em.getTransaction().commit();
em.close();
}
use of org.hibernate.envers.test.Priority in project hibernate-orm by hibernate.
the class HasChangedManyToOneInComponent 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();
ManyToOneComponentTestEntity mtocte1 = new ManyToOneComponentTestEntity(new ManyToOneComponent(ste1, "data1"));
em.persist(mtocte1);
em.getTransaction().commit();
// Revision 3
em = getEntityManager();
em.getTransaction().begin();
mtocte1 = em.find(ManyToOneComponentTestEntity.class, mtocte1.getId());
mtocte1.getComp1().setEntity(ste2);
em.getTransaction().commit();
mtocte_id1 = mtocte1.getId();
}
Aggregations