Search in sources :

Example 1 with SetOwnedEntity

use of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity in project hibernate-orm by hibernate.

the class ValidityAuditStrategyManyToManyTest method testHistoryOfIng1.

@Test
public void testHistoryOfIng1() {
    SetOwningEntity ver_empty = createOwningEntity();
    SetOwningEntity ver_child = createOwningEntity(new SetOwnedEntity(ed_id, "child"));
    assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 1), ver_empty);
    assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 2), ver_child);
    assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 3), ver_empty);
    assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 4), ver_child);
    assertEquals(getAuditReader().find(SetOwningEntity.class, ing_id, 5), ver_empty);
}
Also used : SetOwnedEntity(org.hibernate.envers.test.entities.manytomany.SetOwnedEntity) SetOwningEntity(org.hibernate.envers.test.entities.manytomany.SetOwningEntity) Test(org.junit.Test)

Example 2 with SetOwnedEntity

use of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity in project hibernate-orm by hibernate.

the class ValidityAuditStrategyManyToManyTest method createOwningEntity.

private SetOwningEntity createOwningEntity(SetOwnedEntity... owned) {
    SetOwningEntity result = new SetOwningEntity(ing_id, "parent");
    result.setReferences(new HashSet<SetOwnedEntity>());
    for (SetOwnedEntity setOwnedEntity : owned) {
        result.getReferences().add(setOwnedEntity);
    }
    return result;
}
Also used : SetOwnedEntity(org.hibernate.envers.test.entities.manytomany.SetOwnedEntity) SetOwningEntity(org.hibernate.envers.test.entities.manytomany.SetOwningEntity)

Example 3 with SetOwnedEntity

use of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity in project hibernate-orm by hibernate.

the class RemovedObjectQueryTest method testOwningManyToManySameRevision.

@Test
public void testOwningManyToManySameRevision() {
    List queryResult = getAuditReader().createQuery().forRevisionsOfEntity(SetOwnedEntity.class, false, true).add(AuditEntity.id().eq(6)).add(AuditEntity.revisionType().eq(RevisionType.DEL)).getResultList();
    Object[] objArray = (Object[]) queryResult.get(0);
    Assert.assertEquals(7, getRevisionNumber(objArray[1]));
    SetOwnedEntity setOwnedEntity = (SetOwnedEntity) objArray[0];
    Assert.assertEquals("Example Data 1", setOwnedEntity.getData());
    Hibernate.initialize(setOwnedEntity.getReferencing());
    Assert.assertEquals(TestTools.makeSet(new SetOwningEntity(5, "Demo Data 1")), setOwnedEntity.getReferencing());
}
Also used : SetOwnedEntity(org.hibernate.envers.test.entities.manytomany.SetOwnedEntity) ArrayList(java.util.ArrayList) List(java.util.List) SetOwningEntity(org.hibernate.envers.test.entities.manytomany.SetOwningEntity) Test(org.junit.Test)

Example 4 with SetOwnedEntity

use of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity in project hibernate-orm by hibernate.

the class BasicSet method testHistoryOfEdIng1.

@Test
public void testHistoryOfEdIng1() {
    SetOwnedEntity ed1 = getEntityManager().find(SetOwnedEntity.class, ed1_id);
    SetOwnedEntity ed2 = getEntityManager().find(SetOwnedEntity.class, ed2_id);
    SetOwningEntity rev1 = getAuditReader().find(SetOwningEntity.class, ing1_id, 1);
    SetOwningEntity rev2 = getAuditReader().find(SetOwningEntity.class, ing1_id, 2);
    SetOwningEntity rev3 = getAuditReader().find(SetOwningEntity.class, ing1_id, 3);
    SetOwningEntity rev4 = getAuditReader().find(SetOwningEntity.class, ing1_id, 4);
    SetOwningEntity rev5 = getAuditReader().find(SetOwningEntity.class, ing1_id, 5);
    assert rev1.getReferences().equals(Collections.EMPTY_SET);
    assert rev2.getReferences().equals(TestTools.makeSet(ed1));
    assert rev3.getReferences().equals(TestTools.makeSet(ed1, ed2));
    assert rev4.getReferences().equals(TestTools.makeSet(ed2));
    assert rev5.getReferences().equals(Collections.EMPTY_SET);
}
Also used : SetOwnedEntity(org.hibernate.envers.test.entities.manytomany.SetOwnedEntity) SetOwningEntity(org.hibernate.envers.test.entities.manytomany.SetOwningEntity) Test(org.junit.Test)

Example 5 with SetOwnedEntity

use of org.hibernate.envers.test.entities.manytomany.SetOwnedEntity in project hibernate-orm by hibernate.

the class BasicSet method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    SetOwnedEntity ed1 = new SetOwnedEntity(1, "data_ed_1");
    SetOwnedEntity ed2 = new SetOwnedEntity(2, "data_ed_2");
    SetOwningEntity ing1 = new SetOwningEntity(3, "data_ing_1");
    SetOwningEntity ing2 = new SetOwningEntity(4, "data_ing_2");
    // Revision 1
    em.getTransaction().begin();
    em.persist(ed1);
    em.persist(ed2);
    em.persist(ing1);
    em.persist(ing2);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ing1 = em.find(SetOwningEntity.class, ing1.getId());
    ing2 = em.find(SetOwningEntity.class, ing2.getId());
    ed1 = em.find(SetOwnedEntity.class, ed1.getId());
    ed2 = em.find(SetOwnedEntity.class, ed2.getId());
    ing1.setReferences(new HashSet<SetOwnedEntity>());
    ing1.getReferences().add(ed1);
    ing2.setReferences(new HashSet<SetOwnedEntity>());
    ing2.getReferences().add(ed1);
    ing2.getReferences().add(ed2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ing1 = em.find(SetOwningEntity.class, ing1.getId());
    ed2 = em.find(SetOwnedEntity.class, ed2.getId());
    ed1 = em.find(SetOwnedEntity.class, ed1.getId());
    ing1.getReferences().add(ed2);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    ing1 = em.find(SetOwningEntity.class, ing1.getId());
    ed2 = em.find(SetOwnedEntity.class, ed2.getId());
    ed1 = em.find(SetOwnedEntity.class, ed1.getId());
    ing1.getReferences().remove(ed1);
    em.getTransaction().commit();
    // Revision 5
    em.getTransaction().begin();
    ing1 = em.find(SetOwningEntity.class, ing1.getId());
    ing1.setReferences(null);
    em.getTransaction().commit();
    //
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
    ing1_id = ing1.getId();
    ing2_id = ing2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) SetOwnedEntity(org.hibernate.envers.test.entities.manytomany.SetOwnedEntity) SetOwningEntity(org.hibernate.envers.test.entities.manytomany.SetOwningEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

SetOwnedEntity (org.hibernate.envers.test.entities.manytomany.SetOwnedEntity)16 SetOwningEntity (org.hibernate.envers.test.entities.manytomany.SetOwningEntity)15 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)4 List (java.util.List)4 EntityManager (javax.persistence.EntityManager)4 Priority (org.hibernate.envers.test.Priority)4 HashSet (java.util.HashSet)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 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 SetRefEdEntity (org.hibernate.envers.test.entities.onetomany.SetRefEdEntity)1 SetRefIngEntity (org.hibernate.envers.test.entities.onetomany.SetRefIngEntity)1 TernaryMapEntity (org.hibernate.envers.test.integration.manytomany.ternary.TernaryMapEntity)1