Search in sources :

Example 51 with Priority

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

Example 52 with Priority

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();
}
Also used : Car(org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Car) ArrayList(java.util.ArrayList) Person(org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Person) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 53 with Priority

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();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) IdMapKeyEntity(org.hibernate.envers.test.integration.collection.mapkey.IdMapKeyEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 54 with Priority

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();
}
Also used : EntityManager(javax.persistence.EntityManager) BasicTestEntity1(org.hibernate.envers.test.integration.basic.BasicTestEntity1) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 55 with Priority

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();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) ManyToOneComponentTestEntity(org.hibernate.envers.test.entities.components.relations.ManyToOneComponentTestEntity) ManyToOneComponent(org.hibernate.envers.test.entities.components.relations.ManyToOneComponent) 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