Search in sources :

Example 1 with Student

use of org.hibernate.envers.test.integration.modifiedflags.entities.Student 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();
    }
}
Also used : Professor(org.hibernate.envers.test.integration.modifiedflags.entities.Professor) EntityManager(javax.persistence.EntityManager) Student(org.hibernate.envers.test.integration.modifiedflags.entities.Student) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

EntityManager (javax.persistence.EntityManager)1 Priority (org.hibernate.envers.test.Priority)1 Professor (org.hibernate.envers.test.integration.modifiedflags.entities.Professor)1 Student (org.hibernate.envers.test.integration.modifiedflags.entities.Student)1 Test (org.junit.Test)1