Search in sources :

Example 6 with MulId

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

the class BasicDetachedSetWithMulId method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    str1_id = new MulId(1, 2);
    str2_id = new MulId(3, 4);
    coll1_id = new MulId(5, 6);
    MulIdTestEntity str1 = new MulIdTestEntity(str1_id.getId1(), str1_id.getId2(), "str1");
    MulIdTestEntity str2 = new MulIdTestEntity(str2_id.getId1(), str2_id.getId2(), "str2");
    SetRefCollEntityMulId coll1 = new SetRefCollEntityMulId(coll1_id.getId1(), coll1_id.getId2(), "coll1");
    // Revision 1
    em.getTransaction().begin();
    em.persist(str1);
    em.persist(str2);
    coll1.setCollection(new HashSet<MulIdTestEntity>());
    coll1.getCollection().add(str1);
    em.persist(coll1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    str2 = em.find(MulIdTestEntity.class, str2_id);
    coll1 = em.find(SetRefCollEntityMulId.class, coll1_id);
    coll1.getCollection().add(str2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    str1 = em.find(MulIdTestEntity.class, str1_id);
    coll1 = em.find(SetRefCollEntityMulId.class, coll1_id);
    coll1.getCollection().remove(str1);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    coll1 = em.find(SetRefCollEntityMulId.class, coll1_id);
    coll1.getCollection().clear();
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) MulIdTestEntity(org.hibernate.envers.test.entities.ids.MulIdTestEntity) SetRefCollEntityMulId(org.hibernate.envers.test.entities.onetomany.detached.ids.SetRefCollEntityMulId) SetRefCollEntityMulId(org.hibernate.envers.test.entities.onetomany.detached.ids.SetRefCollEntityMulId) MulId(org.hibernate.envers.test.entities.ids.MulId) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 7 with MulId

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

Aggregations

EntityManager (javax.persistence.EntityManager)7 Priority (org.hibernate.envers.test.Priority)7 MulId (org.hibernate.envers.test.entities.ids.MulId)7 Test (org.junit.Test)7 MulIdTestEntity (org.hibernate.envers.test.entities.ids.MulIdTestEntity)3 EmbId (org.hibernate.envers.test.entities.ids.EmbId)2 EmbIdTestEntity (org.hibernate.envers.test.entities.ids.EmbIdTestEntity)2 SetRefEdMulIdEntity (org.hibernate.envers.test.entities.onetomany.ids.SetRefEdMulIdEntity)2 SetRefIngMulIdEntity (org.hibernate.envers.test.entities.onetomany.ids.SetRefIngMulIdEntity)2 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)1 EmbIdWithCustomType (org.hibernate.envers.test.entities.ids.EmbIdWithCustomType)1 EmbIdWithCustomTypeTestEntity (org.hibernate.envers.test.entities.ids.EmbIdWithCustomTypeTestEntity)1 SetRefCollEntityMulId (org.hibernate.envers.test.entities.onetomany.detached.ids.SetRefCollEntityMulId)1