Search in sources :

Example 6 with SetRefIngMulIdEntity

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

the class BasicSetWithMulId method testHistoryOfEdIng1.

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

Example 7 with SetRefIngMulIdEntity

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

the class MulIdOneToManyQuery method testEntitiesReferencedByIng2ToId3.

@Test
public void testEntitiesReferencedByIng2ToId3() {
    List rev1_related = getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1).add(AuditEntity.relatedId("reference").eq(id3)).add(AuditEntity.id().eq(id2)).getResultList();
    List rev2_related = getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2).add(AuditEntity.relatedId("reference").eq(id3)).add(AuditEntity.id().eq(id2)).getResultList();
    Object rev3_related = getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3).add(AuditEntity.relatedId("reference").eq(id3)).add(AuditEntity.id().eq(id2)).getSingleResult();
    assertEquals(0, rev1_related.size());
    assertEquals(0, rev2_related.size());
    assertEquals(new SetRefIngMulIdEntity(id2, "y", null), rev3_related);
}
Also used : SetRefIngMulIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefIngMulIdEntity) List(java.util.List) Test(org.junit.Test)

Example 8 with SetRefIngMulIdEntity

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

the class MulIdOneToManyQuery method initData.

@Test
@Priority(10)
public void initData() {
    id1 = new MulId(0, 1);
    id2 = new MulId(10, 11);
    id3 = new MulId(20, 21);
    id4 = new MulId(30, 31);
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    SetRefIngMulIdEntity refIng1 = new SetRefIngMulIdEntity(id1, "x", null);
    SetRefIngMulIdEntity refIng2 = new SetRefIngMulIdEntity(id2, "y", null);
    em.persist(refIng1);
    em.persist(refIng2);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    SetRefEdMulIdEntity refEd3 = new SetRefEdMulIdEntity(id3, "a");
    SetRefEdMulIdEntity refEd4 = new SetRefEdMulIdEntity(id4, "a");
    em.persist(refEd3);
    em.persist(refEd4);
    refIng1 = em.find(SetRefIngMulIdEntity.class, id1);
    refIng2 = em.find(SetRefIngMulIdEntity.class, id2);
    refIng1.setReference(refEd3);
    refIng2.setReference(refEd4);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    refEd3 = em.find(SetRefEdMulIdEntity.class, id3);
    refIng2 = em.find(SetRefIngMulIdEntity.class, id2);
    refIng2.setReference(refEd3);
    em.getTransaction().commit();
}
Also used : SetRefEdMulIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefEdMulIdEntity) EntityManager(javax.persistence.EntityManager) SetRefIngMulIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefIngMulIdEntity) MulId(org.hibernate.envers.test.entities.ids.MulId) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 9 with SetRefIngMulIdEntity

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

the class MulIdOneToManyQuery method testEntitiesReferencedToId3.

@Test
public void testEntitiesReferencedToId3() {
    Set rev1_related = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1).add(AuditEntity.relatedId("reference").eq(id3)).getResultList());
    Set rev1 = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1).add(AuditEntity.property("reference").eq(new SetRefEdMulIdEntity(id3, null))).getResultList());
    Set rev2_related = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2).add(AuditEntity.relatedId("reference").eq(id3)).getResultList());
    Set rev2 = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2).add(AuditEntity.property("reference").eq(new SetRefEdMulIdEntity(id3, null))).getResultList());
    Set rev3_related = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3).add(AuditEntity.relatedId("reference").eq(id3)).getResultList());
    Set rev3 = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3).add(AuditEntity.property("reference").eq(new SetRefEdMulIdEntity(id3, null))).getResultList());
    assertEquals(rev1, rev1_related);
    assertEquals(rev2, rev2_related);
    assertEquals(rev3, rev3_related);
    assertEquals(rev1, TestTools.makeSet());
    assertEquals(rev2, TestTools.makeSet(new SetRefIngMulIdEntity(id1, "x", null)));
    assertEquals(rev3, TestTools.makeSet(new SetRefIngMulIdEntity(id1, "x", null), new SetRefIngMulIdEntity(id2, "y", null)));
}
Also used : SetRefEdMulIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefEdMulIdEntity) SetRefIngMulIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefIngMulIdEntity) Set(java.util.Set) HashSet(java.util.HashSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with SetRefIngMulIdEntity

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

the class MulIdOneToManyQuery method testEntitiesReferencedByIng1ToId3.

@Test
public void testEntitiesReferencedByIng1ToId3() {
    List rev1_related = getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1).add(AuditEntity.relatedId("reference").eq(id3)).add(AuditEntity.id().eq(id1)).getResultList();
    Object rev2_related = getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2).add(AuditEntity.relatedId("reference").eq(id3)).add(AuditEntity.id().eq(id1)).getSingleResult();
    Object rev3_related = getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3).add(AuditEntity.relatedId("reference").eq(id3)).add(AuditEntity.id().eq(id1)).getSingleResult();
    assertEquals(0, rev1_related.size());
    assertEquals(rev2_related, new SetRefIngMulIdEntity(id1, "x", null));
    assertEquals(rev3_related, new SetRefIngMulIdEntity(id1, "x", null));
}
Also used : SetRefIngMulIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefIngMulIdEntity) List(java.util.List) Test(org.junit.Test)

Aggregations

SetRefIngMulIdEntity (org.hibernate.envers.test.entities.onetomany.ids.SetRefIngMulIdEntity)10 Test (org.junit.Test)10 SetRefEdMulIdEntity (org.hibernate.envers.test.entities.onetomany.ids.SetRefEdMulIdEntity)7 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 EntityManager (javax.persistence.EntityManager)2 Priority (org.hibernate.envers.test.Priority)2 MulId (org.hibernate.envers.test.entities.ids.MulId)2