Search in sources :

Example 1 with SetRefEdEmbIdEntity

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

the class BasicSetWithEmbId method initData.

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

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

the class EmbIdOneToManyQuery method testEntitiesReferencedToId3.

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

Example 3 with SetRefEdEmbIdEntity

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

the class BasicSetWithEmbId method testHistoryOfEdIng2.

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

use of org.hibernate.envers.test.entities.onetomany.ids.SetRefEdEmbIdEntity 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 5 with SetRefEdEmbIdEntity

use of org.hibernate.envers.test.entities.onetomany.ids.SetRefEdEmbIdEntity 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

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