Search in sources :

Example 1 with SetRefCollEntity

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

the class DataChangesDetachedSet method testHistoryOfColl1.

@Test
public void testHistoryOfColl1() {
    StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
    SetRefCollEntity rev1 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 1);
    SetRefCollEntity rev2 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 2);
    assert rev1.getCollection().equals(TestTools.makeSet());
    assert rev2.getCollection().equals(TestTools.makeSet(str1));
    assert "coll1".equals(rev1.getData());
    assert "coll2".equals(rev2.getData());
}
Also used : SetRefCollEntity(org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Example 2 with SetRefCollEntity

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

the class BasicDetachedSet method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    StrTestEntity str1 = new StrTestEntity("str1");
    StrTestEntity str2 = new StrTestEntity("str2");
    SetRefCollEntity coll1 = new SetRefCollEntity(3, "coll1");
    // Revision 1
    em.getTransaction().begin();
    em.persist(str1);
    em.persist(str2);
    coll1.setCollection(new HashSet<StrTestEntity>());
    coll1.getCollection().add(str1);
    em.persist(coll1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    str2 = em.find(StrTestEntity.class, str2.getId());
    coll1 = em.find(SetRefCollEntity.class, coll1.getId());
    coll1.getCollection().add(str2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    str1 = em.find(StrTestEntity.class, str1.getId());
    coll1 = em.find(SetRefCollEntity.class, coll1.getId());
    coll1.getCollection().remove(str1);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    coll1 = em.find(SetRefCollEntity.class, coll1.getId());
    coll1.getCollection().clear();
    em.getTransaction().commit();
    //
    str1_id = str1.getId();
    str2_id = str2.getId();
    coll1_id = coll1.getId();
}
Also used : SetRefCollEntity(org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 3 with SetRefCollEntity

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

the class BasicDetachedSet method testHistoryOfColl1.

@Test
public void testHistoryOfColl1() {
    StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
    StrTestEntity str2 = getEntityManager().find(StrTestEntity.class, str2_id);
    SetRefCollEntity rev1 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 1);
    SetRefCollEntity rev2 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 2);
    SetRefCollEntity rev3 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 3);
    SetRefCollEntity rev4 = getAuditReader().find(SetRefCollEntity.class, coll1_id, 4);
    assert rev1.getCollection().equals(TestTools.makeSet(str1));
    assert rev2.getCollection().equals(TestTools.makeSet(str1, str2));
    assert rev3.getCollection().equals(TestTools.makeSet(str2));
    assert rev4.getCollection().equals(TestTools.makeSet());
    assert "coll1".equals(rev1.getData());
    assert "coll1".equals(rev2.getData());
    assert "coll1".equals(rev3.getData());
    assert "coll1".equals(rev4.getData());
}
Also used : SetRefCollEntity(org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Example 4 with SetRefCollEntity

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

the class DataChangesDetachedSet method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    StrTestEntity str1 = new StrTestEntity("str1");
    SetRefCollEntity coll1 = new SetRefCollEntity(3, "coll1");
    // Revision 1
    em.getTransaction().begin();
    em.persist(str1);
    coll1.setCollection(new HashSet<StrTestEntity>());
    em.persist(coll1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    str1 = em.find(StrTestEntity.class, str1.getId());
    coll1 = em.find(SetRefCollEntity.class, coll1.getId());
    coll1.getCollection().add(str1);
    coll1.setData("coll2");
    em.getTransaction().commit();
    //
    str1_id = str1.getId();
    coll1_id = coll1.getId();
}
Also used : SetRefCollEntity(org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity) StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)4 SetRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity)4 Test (org.junit.Test)4 EntityManager (javax.persistence.EntityManager)2 Priority (org.hibernate.envers.test.Priority)2