Search in sources :

Example 1 with UnversionedStrTestEntity

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

the class NotAuditedManyToOneInComponent method initData.

@Test
@Priority(10)
public void initData() {
    // No revision
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    UnversionedStrTestEntity ste1 = new UnversionedStrTestEntity();
    ste1.setStr("str1");
    UnversionedStrTestEntity ste2 = new UnversionedStrTestEntity();
    ste2.setStr("str2");
    em.persist(ste1);
    em.persist(ste2);
    em.getTransaction().commit();
    // Revision 1
    em = getEntityManager();
    em.getTransaction().begin();
    NotAuditedManyToOneComponentTestEntity mtocte1 = new NotAuditedManyToOneComponentTestEntity(new NotAuditedManyToOneComponent(ste1, "data1"));
    em.persist(mtocte1);
    em.getTransaction().commit();
    // No revision
    em = getEntityManager();
    em.getTransaction().begin();
    mtocte1 = em.find(NotAuditedManyToOneComponentTestEntity.class, mtocte1.getId());
    mtocte1.getComp1().setEntity(ste2);
    em.getTransaction().commit();
    // Revision 2
    em = getEntityManager();
    em.getTransaction().begin();
    mtocte1 = em.find(NotAuditedManyToOneComponentTestEntity.class, mtocte1.getId());
    mtocte1.getComp1().setData("data2");
    em.getTransaction().commit();
    mtocte_id1 = mtocte1.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) NotAuditedManyToOneComponentTestEntity(org.hibernate.envers.test.entities.components.relations.NotAuditedManyToOneComponentTestEntity) UnversionedStrTestEntity(org.hibernate.envers.test.entities.UnversionedStrTestEntity) NotAuditedManyToOneComponent(org.hibernate.envers.test.entities.components.relations.NotAuditedManyToOneComponent) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 2 with UnversionedStrTestEntity

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

the class RelationNotAuditedTarget method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity("str1");
    UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity("str2");
    // No revision
    em.getTransaction().begin();
    em.persist(uste1);
    em.persist(uste2);
    em.getTransaction().commit();
    // Revision 1
    em.getTransaction().begin();
    uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId());
    uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId());
    TargetNotAuditedEntity tnae1 = new TargetNotAuditedEntity(1, "tnae1", uste1);
    TargetNotAuditedEntity tnae2 = new TargetNotAuditedEntity(2, "tnae2", uste2);
    em.persist(tnae1);
    em.persist(tnae2);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
    tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
    tnae1.setReference(uste2);
    tnae2.setReference(uste1);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
    tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
    // field not changed!!!
    tnae1.setReference(uste2);
    tnae2.setReference(uste2);
    em.getTransaction().commit();
    // Revision 4
    em.getTransaction().begin();
    tnae1 = em.find(TargetNotAuditedEntity.class, tnae1.getId());
    tnae2 = em.find(TargetNotAuditedEntity.class, tnae2.getId());
    tnae1.setReference(uste1);
    tnae2.setReference(uste1);
    em.getTransaction().commit();
    // 
    tnae1_id = tnae1.getId();
    tnae2_id = tnae2.getId();
    uste1_id = uste1.getId();
    uste2_id = uste2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) UnversionedStrTestEntity(org.hibernate.envers.test.entities.UnversionedStrTestEntity) TargetNotAuditedEntity(org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAuditedEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 3 with UnversionedStrTestEntity

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

the class M2MIndexedListNotAuditedTarget method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    uste1 = new UnversionedStrTestEntity("str1");
    uste2 = new UnversionedStrTestEntity("str2");
    // No revision
    em.getTransaction().begin();
    em.persist(uste1);
    em.persist(uste2);
    em.getTransaction().commit();
    // Revision 1
    em.getTransaction().begin();
    uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId());
    uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId());
    M2MIndexedListTargetNotAuditedEntity itnae1 = new M2MIndexedListTargetNotAuditedEntity(1, "tnae1");
    itnae1.getReferences().add(uste1);
    itnae1.getReferences().add(uste2);
    em.persist(itnae1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    M2MIndexedListTargetNotAuditedEntity itnae2 = new M2MIndexedListTargetNotAuditedEntity(2, "tnae2");
    itnae2.getReferences().add(uste2);
    em.persist(itnae2);
    em.getTransaction().commit();
    // Revision 3
    em.getTransaction().begin();
    itnae1.getReferences().set(0, uste2);
    itnae1.getReferences().set(1, uste1);
    em.getTransaction().commit();
    itnae1_id = itnae1.getId();
    itnae2_id = itnae2.getId();
}
Also used : EntityManager(javax.persistence.EntityManager) M2MIndexedListTargetNotAuditedEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.M2MIndexedListTargetNotAuditedEntity) UnversionedStrTestEntity(org.hibernate.envers.test.entities.UnversionedStrTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 4 with UnversionedStrTestEntity

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

the class M2MRelationNotAuditedTarget method testHistoryOfTnae1_id.

@Test
public void testHistoryOfTnae1_id() {
    UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
    UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
    M2MTargetNotAuditedEntity rev1 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 1);
    M2MTargetNotAuditedEntity rev2 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 2);
    M2MTargetNotAuditedEntity rev3 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 3);
    M2MTargetNotAuditedEntity rev4 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 4);
    assertTrue(checkCollection(rev1.getReferences()));
    assertTrue(checkCollection(rev2.getReferences(), uste1));
    assertTrue(checkCollection(rev3.getReferences(), uste1));
    assertTrue(checkCollection(rev4.getReferences(), uste1, uste2));
}
Also used : M2MTargetNotAuditedEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.M2MTargetNotAuditedEntity) UnversionedStrTestEntity(org.hibernate.envers.test.entities.UnversionedStrTestEntity) Test(org.junit.Test)

Example 5 with UnversionedStrTestEntity

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

the class M2MRelationNotAuditedTarget method testHistoryOfTnae2_id.

@Test
public void testHistoryOfTnae2_id() {
    UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
    UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
    M2MTargetNotAuditedEntity rev1 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 1);
    M2MTargetNotAuditedEntity rev2 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 2);
    M2MTargetNotAuditedEntity rev3 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 3);
    M2MTargetNotAuditedEntity rev4 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 4);
    assertTrue(checkCollection(rev1.getReferences(), uste1, uste2));
    assertTrue(checkCollection(rev2.getReferences(), uste2));
    assertTrue(checkCollection(rev3.getReferences()));
    assertTrue(checkCollection(rev4.getReferences(), uste1));
}
Also used : M2MTargetNotAuditedEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.M2MTargetNotAuditedEntity) UnversionedStrTestEntity(org.hibernate.envers.test.entities.UnversionedStrTestEntity) Test(org.junit.Test)

Aggregations

UnversionedStrTestEntity (org.hibernate.envers.test.entities.UnversionedStrTestEntity)11 Test (org.junit.Test)11 EntityManager (javax.persistence.EntityManager)7 Priority (org.hibernate.envers.test.Priority)7 TargetNotAuditedEntity (org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAuditedEntity)4 M2MTargetNotAuditedEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.M2MTargetNotAuditedEntity)3 M2MIndexedListTargetNotAuditedEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.M2MIndexedListTargetNotAuditedEntity)2 HashSet (java.util.HashSet)1 IntTestPrivSeqEntity (org.hibernate.envers.test.entities.IntTestPrivSeqEntity)1 StrTestPrivSeqEntity (org.hibernate.envers.test.entities.StrTestPrivSeqEntity)1 StringSetEntity (org.hibernate.envers.test.entities.collection.StringSetEntity)1 NotAuditedManyToOneComponent (org.hibernate.envers.test.entities.components.relations.NotAuditedManyToOneComponent)1 NotAuditedManyToOneComponentTestEntity (org.hibernate.envers.test.entities.components.relations.NotAuditedManyToOneComponentTestEntity)1 ManyToOneIdNotAuditedTestEntity (org.hibernate.envers.test.entities.ids.ManyToOneIdNotAuditedTestEntity)1 ManyToOneNotAuditedEmbId (org.hibernate.envers.test.entities.ids.ManyToOneNotAuditedEmbId)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 ManyToManyNotAuditedNullEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.ManyToManyNotAuditedNullEntity)1