Search in sources :

Example 11 with SetRefIngEntity

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

the class BasicSetWithNullsDelete method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1");
    SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2");
    SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1", ed1);
    SetRefIngEntity ing2 = new SetRefIngEntity(4, "data_ing_2", ed1);
    SetRefIngEntity ing3 = new SetRefIngEntity(5, "data_ing_3", ed1);
    SetRefIngEntity ing4 = new SetRefIngEntity(6, "data_ing_4", ed1);
    // Revision 1
    em.getTransaction().begin();
    em.persist(ed1);
    em.persist(ed2);
    em.persist(ing1);
    em.persist(ing2);
    em.persist(ing3);
    em.persist(ing4);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    ing1 = em.find(SetRefIngEntity.class, ing1.getId());
    ing1.setReference(null);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    ing2 = em.find(SetRefIngEntity.class, ing2.getId());
    em.remove(ing2);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    ing3 = em.find(SetRefIngEntity.class, ing3.getId());
    ed2 = em.find(SetRefEdEntity.class, ed2.getId());
    ing3.setReference(ed2);
    em.getTransaction().commit();
    // Revision 5
    em.getTransaction().begin();
    ing4 = em.find(SetRefIngEntity.class, ing4.getId());
    ed1 = em.find(SetRefEdEntity.class, ed1.getId());
    em.remove(ed1);
    ing4.setReference(null);
    em.getTransaction().commit();
    //
    ed1_id = ed1.getId();
    ed2_id = ed2.getId();
    ing1_id = ing1.getId();
    ing2_id = ing2.getId();
    ing3_id = ing3.getId();
    ing4_id = ing4.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 12 with SetRefIngEntity

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

the class BasicSetWithNullsDelete method testHistoryOfEdIng1.

@Test
public void testHistoryOfEdIng1() {
    SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1");
    SetRefIngEntity rev1 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 1);
    SetRefIngEntity rev2 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 2);
    SetRefIngEntity rev3 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 3);
    SetRefIngEntity rev4 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 4);
    SetRefIngEntity rev5 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 5);
    assert rev1.getReference().equals(ed1);
    assert rev2.getReference() == null;
    assert rev3.getReference() == null;
    assert rev4.getReference() == null;
    assert rev5.getReference() == null;
}
Also used : SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) Test(org.junit.Test)

Example 13 with SetRefIngEntity

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

the class OneToManyJtaSessionClosedBeforeCommitTest method initData.

@Test
@Priority(10)
public void initData() throws Exception {
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
    EntityManager entityManager = getEntityManager();
    try {
        SetRefEdEntity edEntity = new SetRefEdEntity(2, "edEntity");
        entityManager.persist(edEntity);
        SetRefIngEntity ingEntity = new SetRefIngEntity(1, "ingEntity");
        Set<SetRefIngEntity> sries = new HashSet<>();
        sries.add(ingEntity);
        ingEntity.setReference(edEntity);
        edEntity.setReffering(sries);
        entityManager.persist(ingEntity);
        entityId = ingEntity.getId();
        // simulates spring JtaTransactionManager.triggerBeforeCompletion()
        // this closes the entity manager prior to the JTA transaction.
        entityManager.close();
    } finally {
        TestingJtaPlatformImpl.tryCommit();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) HashSet(java.util.HashSet) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 14 with SetRefIngEntity

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

the class EvictAuditDataAfterCommitTest method testSessionCacheCollectionClear.

@Test
@TestForIssue(jiraKey = "HHH-6614")
public void testSessionCacheCollectionClear() {
    final String[] auditEntityNames = new String[] { "org.hibernate.envers.test.entities.onetomany.SetRefEdEntity_AUD", "org.hibernate.envers.test.entities.onetomany.SetRefIngEntity_AUD" };
    SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1");
    SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2");
    SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1");
    SetRefIngEntity ing2 = new SetRefIngEntity(4, "data_ing_2");
    Session session = openSession();
    session.getTransaction().begin();
    session.persist(ed1);
    session.persist(ed2);
    session.persist(ing1);
    session.persist(ing2);
    session.getTransaction().commit();
    checkEmptyAuditSessionCache(session, auditEntityNames);
    session.getTransaction().begin();
    ed1 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed1.getId());
    ing1.setReference(ed1);
    ing2.setReference(ed1);
    session.getTransaction().commit();
    checkEmptyAuditSessionCache(session, auditEntityNames);
    session.getTransaction().begin();
    ed2 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed2.getId());
    Set<SetRefIngEntity> reffering = new HashSet<SetRefIngEntity>();
    reffering.add(ing1);
    reffering.add(ing2);
    ed2.setReffering(reffering);
    session.getTransaction().commit();
    checkEmptyAuditSessionCache(session, auditEntityNames);
    session.getTransaction().begin();
    ed2 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed2.getId());
    ed2.getReffering().remove(ing1);
    session.getTransaction().commit();
    checkEmptyAuditSessionCache(session, auditEntityNames);
    session.getTransaction().begin();
    ed2 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed2.getId());
    ed2.getReffering().iterator().next().setData("mod_data_ing_2");
    session.getTransaction().commit();
    checkEmptyAuditSessionCache(session, auditEntityNames);
    session.close();
}
Also used : SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) Session(org.hibernate.Session) HashSet(java.util.HashSet) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 15 with SetRefIngEntity

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

the class RemovedObjectQueryTest method testReferringOneToManySameRevision.

@Test
public void testReferringOneToManySameRevision() {
    List queryResult = getAuditReader().createQuery().forRevisionsOfEntity(SetRefEdEntity.class, false, true).add(AuditEntity.id().eq(1)).add(AuditEntity.revisionType().eq(RevisionType.DEL)).getResultList();
    Object[] objArray = (Object[]) queryResult.get(0);
    Assert.assertEquals(2, getRevisionNumber(objArray[1]));
    SetRefEdEntity refEdEntity = (SetRefEdEntity) objArray[0];
    Assert.assertEquals("Demo Data 1", refEdEntity.getData());
    Hibernate.initialize(refEdEntity.getReffering());
    Assert.assertEquals(TestTools.makeSet(new SetRefIngEntity(2, "Example Data 1")), refEdEntity.getReffering());
}
Also used : SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

SetRefIngEntity (org.hibernate.envers.test.entities.onetomany.SetRefIngEntity)22 Test (org.junit.Test)22 SetRefEdEntity (org.hibernate.envers.test.entities.onetomany.SetRefEdEntity)20 EntityManager (javax.persistence.EntityManager)6 Priority (org.hibernate.envers.test.Priority)6 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Session (org.hibernate.Session)1 IntTestPrivSeqEntity (org.hibernate.envers.test.entities.IntTestPrivSeqEntity)1 StrTestPrivSeqEntity (org.hibernate.envers.test.entities.StrTestPrivSeqEntity)1 UnversionedStrTestEntity (org.hibernate.envers.test.entities.UnversionedStrTestEntity)1 StringSetEntity (org.hibernate.envers.test.entities.collection.StringSetEntity)1 ListOwnedEntity (org.hibernate.envers.test.entities.manytomany.ListOwnedEntity)1 ListOwningEntity (org.hibernate.envers.test.entities.manytomany.ListOwningEntity)1 SetOwnedEntity (org.hibernate.envers.test.entities.manytomany.SetOwnedEntity)1 SetOwningEntity (org.hibernate.envers.test.entities.manytomany.SetOwningEntity)1 M2MIndexedListTargetNotAuditedEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.M2MIndexedListTargetNotAuditedEntity)1 CollectionRefEdEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity)1 CollectionRefIngEntity (org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity)1