Search in sources :

Example 1 with SetRefIngMulIdEntity

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

the class MulIdOneToManyQuery method testEntitiesReferencedToId4.

@Test
public void testEntitiesReferencedToId4() {
    Set rev1_related = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1).add(AuditEntity.relatedId("reference").eq(id4)).getResultList());
    Set rev2_related = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2).add(AuditEntity.relatedId("reference").eq(id4)).getResultList());
    Set rev3_related = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3).add(AuditEntity.relatedId("reference").eq(id4)).getResultList());
    assertEquals(rev1_related, TestTools.makeSet());
    assertEquals(rev2_related, TestTools.makeSet(new SetRefIngMulIdEntity(id2, "y", null)));
    assertEquals(rev3_related, TestTools.makeSet());
}
Also used : 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 2 with SetRefIngMulIdEntity

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

the class BasicSetWithMulId method initData.

@Test
@Priority(10)
public void initData() {
    ed1_id = new MulId(0, 1);
    ed2_id = new MulId(2, 3);
    ing2_id = new MulId(4, 5);
    ing1_id = new MulId(6, 7);
    EntityManager em = getEntityManager();
    SetRefEdMulIdEntity ed1 = new SetRefEdMulIdEntity(ed1_id.getId1(), ed1_id.getId2(), "data_ed_1");
    SetRefEdMulIdEntity ed2 = new SetRefEdMulIdEntity(ed2_id.getId1(), ed2_id.getId2(), "data_ed_2");
    SetRefIngMulIdEntity ing1 = new SetRefIngMulIdEntity(ing1_id.getId1(), ing1_id.getId2(), "data_ing_1", ed1);
    SetRefIngMulIdEntity ing2 = new SetRefIngMulIdEntity(ing2_id.getId1(), ing2_id.getId2(), "data_ing_2", ed1);
    // 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(SetRefIngMulIdEntity.class, ing1_id);
    ed2 = em.find(SetRefEdMulIdEntity.class, ed2_id);
    ing1.setReference(ed2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ing2 = em.find(SetRefIngMulIdEntity.class, ing2_id);
    ed2 = em.find(SetRefEdMulIdEntity.class, ed2_id);
    ing2.setReference(ed2);
    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 3 with SetRefIngMulIdEntity

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

the class BasicSetWithMulId method testHistoryOfEdId1.

@Test
public void testHistoryOfEdId1() {
    SetRefIngMulIdEntity ing1 = getEntityManager().find(SetRefIngMulIdEntity.class, ing1_id);
    SetRefIngMulIdEntity ing2 = getEntityManager().find(SetRefIngMulIdEntity.class, ing2_id);
    SetRefEdMulIdEntity rev1 = getAuditReader().find(SetRefEdMulIdEntity.class, ed1_id, 1);
    SetRefEdMulIdEntity rev2 = getAuditReader().find(SetRefEdMulIdEntity.class, ed1_id, 2);
    SetRefEdMulIdEntity rev3 = getAuditReader().find(SetRefEdMulIdEntity.class, ed1_id, 3);
    assert rev1.getReffering().equals(makeSet(ing1, ing2));
    assert rev2.getReffering().equals(makeSet(ing2));
    assert rev3.getReffering().equals(Collections.EMPTY_SET);
}
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 4 with SetRefIngMulIdEntity

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

the class BasicSetWithMulId method testHistoryOfEdId2.

@Test
public void testHistoryOfEdId2() {
    SetRefIngMulIdEntity ing1 = getEntityManager().find(SetRefIngMulIdEntity.class, ing1_id);
    SetRefIngMulIdEntity ing2 = getEntityManager().find(SetRefIngMulIdEntity.class, ing2_id);
    SetRefEdMulIdEntity rev1 = getAuditReader().find(SetRefEdMulIdEntity.class, ed2_id, 1);
    SetRefEdMulIdEntity rev2 = getAuditReader().find(SetRefEdMulIdEntity.class, ed2_id, 2);
    SetRefEdMulIdEntity rev3 = getAuditReader().find(SetRefEdMulIdEntity.class, ed2_id, 3);
    assert rev1.getReffering().equals(Collections.EMPTY_SET);
    assert rev2.getReffering().equals(makeSet(ing1));
    assert rev3.getReffering().equals(makeSet(ing1, ing2));
}
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 5 with SetRefIngMulIdEntity

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

the class BasicSetWithMulId method testHistoryOfEdIng2.

@Test
public void testHistoryOfEdIng2() {
    SetRefEdMulIdEntity ed1 = getEntityManager().find(SetRefEdMulIdEntity.class, ed1_id);
    SetRefEdMulIdEntity ed2 = getEntityManager().find(SetRefEdMulIdEntity.class, ed2_id);
    SetRefIngMulIdEntity rev1 = getAuditReader().find(SetRefIngMulIdEntity.class, ing2_id, 1);
    SetRefIngMulIdEntity rev2 = getAuditReader().find(SetRefIngMulIdEntity.class, ing2_id, 2);
    SetRefIngMulIdEntity rev3 = getAuditReader().find(SetRefIngMulIdEntity.class, ing2_id, 3);
    assert rev1.getReference().equals(ed1);
    assert rev2.getReference().equals(ed1);
    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)

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