Search in sources :

Example 6 with SetRefIngEmbIdEntity

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

the class EmbIdOneToManyQuery method testEntitiesReferencedToId4.

@Test
public void testEntitiesReferencedToId4() {
    Set rev1_related = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1).add(AuditEntity.relatedId("reference").eq(id4)).getResultList());
    Set rev2_related = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2).add(AuditEntity.relatedId("reference").eq(id4)).getResultList());
    Set rev3_related = new HashSet(getAuditReader().createQuery().forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3).add(AuditEntity.relatedId("reference").eq(id4)).getResultList());
    assert rev1_related.equals(TestTools.makeSet());
    assert rev2_related.equals(TestTools.makeSet(new SetRefIngEmbIdEntity(id2, "y", null)));
    assert rev3_related.equals(TestTools.makeSet());
}
Also used : SetRefIngEmbIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefIngEmbIdEntity) HashSet(java.util.HashSet) Set(java.util.Set) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with SetRefIngEmbIdEntity

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

the class EmbIdOneToManyQuery method initData.

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

Example 8 with SetRefIngEmbIdEntity

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

the class EmbIdOneToManyQuery method testEntitiesReferencedByIng1ToId3.

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

Example 9 with SetRefIngEmbIdEntity

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

the class BasicSetWithEmbId method testHistoryOfEdIng1.

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

Example 10 with SetRefIngEmbIdEntity

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

the class BasicSetWithEmbId method testHistoryOfEdId2.

@Test
public void testHistoryOfEdId2() {
    SetRefIngEmbIdEntity ing1 = getEntityManager().find(SetRefIngEmbIdEntity.class, ing1_id);
    SetRefIngEmbIdEntity ing2 = getEntityManager().find(SetRefIngEmbIdEntity.class, ing2_id);
    SetRefEdEmbIdEntity rev1 = getAuditReader().find(SetRefEdEmbIdEntity.class, ed2_id, 1);
    SetRefEdEmbIdEntity rev2 = getAuditReader().find(SetRefEdEmbIdEntity.class, ed2_id, 2);
    SetRefEdEmbIdEntity rev3 = getAuditReader().find(SetRefEdEmbIdEntity.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 : SetRefIngEmbIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefIngEmbIdEntity) SetRefEdEmbIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefEdEmbIdEntity) Test(org.junit.Test)

Aggregations

SetRefIngEmbIdEntity (org.hibernate.envers.test.entities.onetomany.ids.SetRefIngEmbIdEntity)11 Test (org.junit.Test)11 SetRefEdEmbIdEntity (org.hibernate.envers.test.entities.onetomany.ids.SetRefEdEmbIdEntity)7 EntityManager (javax.persistence.EntityManager)3 Priority (org.hibernate.envers.test.Priority)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 EmbId (org.hibernate.envers.test.entities.ids.EmbId)2 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)1 CollectionRefEdEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity)1 CollectionRefIngEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity)1