Search in sources :

Example 6 with SetRefIngEntity

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

the class RemovedObjectQueryTest method testReferencedOneToManyDifferentRevisions.

@Test
public void testReferencedOneToManyDifferentRevisions() {
    List queryResult = getAuditReader().createQuery().forRevisionsOfEntity(SetRefIngEntity.class, false, true).add(AuditEntity.id().eq(4)).add(AuditEntity.revisionType().eq(RevisionType.DEL)).getResultList();
    Object[] objArray = (Object[]) queryResult.get(0);
    Assert.assertEquals(4, getRevisionNumber(objArray[1]));
    SetRefIngEntity refIngEntity = (SetRefIngEntity) objArray[0];
    Assert.assertEquals("Example Data 2", refIngEntity.getData());
    Hibernate.initialize(refIngEntity.getReference());
    Assert.assertEquals("Demo Data 2", refIngEntity.getReference().getData());
}
Also used : SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 7 with SetRefIngEntity

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

the class InverseSideChanges method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1");
    SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1");
    // Revision 1
    em.getTransaction().begin();
    em.persist(ed1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ed1 = em.find(SetRefEdEntity.class, ed1.getId());
    em.persist(ing1);
    ed1.setReffering(new HashSet<SetRefIngEntity>());
    ed1.getReffering().add(ing1);
    em.getTransaction().commit();
    //
    ed1_id = ed1.getId();
    ing1_id = ing1.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 8 with SetRefIngEntity

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

the class BasicSetWithNullsDelete method testHistoryOfEdIng2.

@Test
public void testHistoryOfEdIng2() {
    SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1");
    SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 1);
    SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 2);
    SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 3);
    SetRefIngEntity rev4 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 4);
    SetRefIngEntity rev5 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 5);
    assert rev1.getReference().equals(ed1);
    assert rev2.getReference().equals(ed1);
    assert rev3 == null;
    assert rev4 == null;
    assert rev5 == null;
}
Also used : SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) Test(org.junit.Test)

Example 9 with SetRefIngEntity

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

the class BasicSetWithNullsDelete method testHistoryOfEdId1.

@Test
public void testHistoryOfEdId1() {
    SetRefIngEntity ing1 = getEntityManager().find(SetRefIngEntity.class, ing1_id);
    SetRefIngEntity ing2 = new SetRefIngEntity(4, "data_ing_2", new SetRefEdEntity(1, "data_ed_1"));
    SetRefIngEntity ing3 = getEntityManager().find(SetRefIngEntity.class, ing3_id);
    SetRefIngEntity ing4 = getEntityManager().find(SetRefIngEntity.class, ing4_id);
    SetRefEdEntity rev1 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 1);
    SetRefEdEntity rev2 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 2);
    SetRefEdEntity rev3 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 3);
    SetRefEdEntity rev4 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 4);
    SetRefEdEntity rev5 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 5);
    assert rev1.getReffering().equals(makeSet(ing1, ing2, ing3, ing4));
    assert rev2.getReffering().equals(makeSet(ing2, ing3, ing4));
    assert rev3.getReffering().equals(makeSet(ing3, ing4));
    assert rev4.getReffering().equals(makeSet(ing4));
    assert rev5 == null;
}
Also used : SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) Test(org.junit.Test)

Example 10 with SetRefIngEntity

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

the class BasicSetWithNullsDelete method testHistoryOfEdId2.

@Test
public void testHistoryOfEdId2() {
    SetRefIngEntity ing3 = getEntityManager().find(SetRefIngEntity.class, ing3_id);
    SetRefEdEntity rev1 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 1);
    SetRefEdEntity rev2 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 2);
    SetRefEdEntity rev3 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 3);
    SetRefEdEntity rev4 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 4);
    SetRefEdEntity rev5 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 5);
    assert rev1.getReffering().equals(Collections.EMPTY_SET);
    assert rev2.getReffering().equals(Collections.EMPTY_SET);
    assert rev3.getReffering().equals(Collections.EMPTY_SET);
    assert rev4.getReffering().equals(makeSet(ing3));
    assert rev5.getReffering().equals(makeSet(ing3));
}
Also used : SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) Test(org.junit.Test)

Aggregations

SetRefIngEntity (org.hibernate.envers.test.entities.onetomany.SetRefIngEntity)22 Test (org.junit.Test)22 SetRefEdEntity (org.hibernate.envers.test.entities.onetomany.SetRefEdEntity)20 EntityManager (javax.persistence.EntityManager)6 Priority (org.hibernate.envers.test.Priority)6 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Session (org.hibernate.Session)1 IntTestPrivSeqEntity (org.hibernate.envers.test.entities.IntTestPrivSeqEntity)1 StrTestPrivSeqEntity (org.hibernate.envers.test.entities.StrTestPrivSeqEntity)1 UnversionedStrTestEntity (org.hibernate.envers.test.entities.UnversionedStrTestEntity)1 StringSetEntity (org.hibernate.envers.test.entities.collection.StringSetEntity)1 ListOwnedEntity (org.hibernate.envers.test.entities.manytomany.ListOwnedEntity)1 ListOwningEntity (org.hibernate.envers.test.entities.manytomany.ListOwningEntity)1 SetOwnedEntity (org.hibernate.envers.test.entities.manytomany.SetOwnedEntity)1 SetOwningEntity (org.hibernate.envers.test.entities.manytomany.SetOwningEntity)1 M2MIndexedListTargetNotAuditedEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.M2MIndexedListTargetNotAuditedEntity)1 CollectionRefEdEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity)1 CollectionRefIngEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity)1