Search in sources :

Example 1 with SetRefIngEmbIdEntity

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

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

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

the class EmbIdOneToManyQuery method testEntitiesReferencedByIng2ToId3.

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

Example 4 with SetRefIngEmbIdEntity

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

the class NullPropertyQuery method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    StrIntTestEntity nullSite = new StrIntTestEntity(null, 1);
    StrIntTestEntity notNullSite = new StrIntTestEntity("data", 2);
    em.persist(nullSite);
    em.persist(notNullSite);
    idSimplePropertyNull = nullSite.getId();
    idSimplePropertyNotNull = notNullSite.getId();
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    SetRefIngEmbIdEntity nullParentSrieie = new SetRefIngEmbIdEntity(idMulticolumnReferenceToParentNull, "data", null);
    em.persist(nullParentSrieie);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    CollectionRefEdEntity parent = new CollectionRefEdEntity(idParent, "data");
    CollectionRefIngEntity notNullParentCrie = new CollectionRefIngEntity(idReferenceToParentNotNull, "data", parent);
    em.persist(parent);
    em.persist(notNullParentCrie);
    em.getTransaction().commit();
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) EntityManager(javax.persistence.EntityManager) SetRefIngEmbIdEntity(org.hibernate.envers.test.entities.onetomany.ids.SetRefIngEmbIdEntity) CollectionRefIngEntity(org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity) CollectionRefEdEntity(org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 5 with SetRefIngEmbIdEntity

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

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