Search in sources :

Example 6 with ListRefIngEntity

use of org.hibernate.envers.test.entities.onetomany.ListRefIngEntity in project hibernate-orm by hibernate.

the class BasicList method testHistoryOfEdIng1.

@Test
public void testHistoryOfEdIng1() {
    ListRefEdEntity ed1 = getEntityManager().find(ListRefEdEntity.class, ed1_id);
    ListRefEdEntity ed2 = getEntityManager().find(ListRefEdEntity.class, ed2_id);
    ListRefIngEntity rev1 = getAuditReader().find(ListRefIngEntity.class, ing1_id, 1);
    ListRefIngEntity rev2 = getAuditReader().find(ListRefIngEntity.class, ing1_id, 2);
    ListRefIngEntity rev3 = getAuditReader().find(ListRefIngEntity.class, ing1_id, 3);
    assert rev1.getReference().equals(ed1);
    assert rev2.getReference().equals(ed2);
    assert rev3.getReference().equals(ed2);
}
Also used : ListRefIngEntity(org.hibernate.envers.test.entities.onetomany.ListRefIngEntity) ListRefEdEntity(org.hibernate.envers.test.entities.onetomany.ListRefEdEntity) Test(org.junit.Test)

Example 7 with ListRefIngEntity

use of org.hibernate.envers.test.entities.onetomany.ListRefIngEntity in project hibernate-orm by hibernate.

the class BasicList method testHistoryOfEdIng2.

@Test
public void testHistoryOfEdIng2() {
    ListRefEdEntity ed1 = getEntityManager().find(ListRefEdEntity.class, ed1_id);
    ListRefEdEntity ed2 = getEntityManager().find(ListRefEdEntity.class, ed2_id);
    ListRefIngEntity rev1 = getAuditReader().find(ListRefIngEntity.class, ing2_id, 1);
    ListRefIngEntity rev2 = getAuditReader().find(ListRefIngEntity.class, ing2_id, 2);
    ListRefIngEntity rev3 = getAuditReader().find(ListRefIngEntity.class, ing2_id, 3);
    assert rev1.getReference().equals(ed1);
    assert rev2.getReference().equals(ed1);
    assert rev3.getReference().equals(ed2);
}
Also used : ListRefIngEntity(org.hibernate.envers.test.entities.onetomany.ListRefIngEntity) ListRefEdEntity(org.hibernate.envers.test.entities.onetomany.ListRefEdEntity) Test(org.junit.Test)

Example 8 with ListRefIngEntity

use of org.hibernate.envers.test.entities.onetomany.ListRefIngEntity in project hibernate-orm by hibernate.

the class HasChangedMergeTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1 - data preparation
    em.getTransaction().begin();
    ListRefEdEntity parent1 = new ListRefEdEntity(1, "initial data");
    // Empty collection is not the same as null reference.
    parent1.setReffering(new ArrayList<ListRefIngEntity>());
    ListRefEdEntity parent2 = new ListRefEdEntity(2, "initial data");
    parent2.setReffering(new ArrayList<ListRefIngEntity>());
    em.persist(parent1);
    em.persist(parent2);
    em.getTransaction().commit();
    // Revision 2 - inserting new child entity and updating parent
    em.getTransaction().begin();
    parent1 = em.find(ListRefEdEntity.class, parent1.getId());
    ListRefIngEntity child1 = new ListRefIngEntity(1, "initial data", parent1);
    em.persist(child1);
    parent1.setData("updated data");
    parent1 = em.merge(parent1);
    em.getTransaction().commit();
    // Revision 3 - updating parent, flushing and adding new child
    em.getTransaction().begin();
    parent2 = em.find(ListRefEdEntity.class, parent2.getId());
    parent2.setData("updated data");
    parent2 = em.merge(parent2);
    em.flush();
    ListRefIngEntity child2 = new ListRefIngEntity(2, "initial data", parent2);
    em.persist(child2);
    em.getTransaction().commit();
    parent1Id = parent1.getId();
    child1Id = child1.getId();
    parent2Id = parent2.getId();
    child2Id = child2.getId();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) ListRefIngEntity(org.hibernate.envers.test.entities.onetomany.ListRefIngEntity) ListRefEdEntity(org.hibernate.envers.test.entities.onetomany.ListRefEdEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

ListRefEdEntity (org.hibernate.envers.test.entities.onetomany.ListRefEdEntity)8 ListRefIngEntity (org.hibernate.envers.test.entities.onetomany.ListRefIngEntity)8 Test (org.junit.Test)8 EntityManager (javax.persistence.EntityManager)4 Priority (org.hibernate.envers.test.Priority)3 HibernateProxy (org.hibernate.proxy.HibernateProxy)1