Search in sources :

Example 6 with UnversionedStrTestEntity

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

the class RelationNotAuditedTarget method testHistoryOfTnae2_id.

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

Example 7 with UnversionedStrTestEntity

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

the class RelationNotAuditedTarget method testHistoryOfTnae1_id.

@Test
public void testHistoryOfTnae1_id() {
    // load original "tnae1" TargetNotAuditedEntity to force load "str1" UnversionedStrTestEntity as Proxy
    TargetNotAuditedEntity original = getEntityManager().find(TargetNotAuditedEntity.class, tnae1_id);
    UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
    UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
    TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 1);
    TargetNotAuditedEntity rev2 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 2);
    TargetNotAuditedEntity rev3 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 3);
    TargetNotAuditedEntity rev4 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1_id, 4);
    assert rev1.getReference().equals(uste1);
    assert rev2.getReference().equals(uste2);
    assert rev3.getReference().equals(uste2);
    assert rev4.getReference().equals(uste1);
    assert original.getReference() instanceof HibernateProxy;
    assert UnversionedStrTestEntity.class.equals(Hibernate.getClass(original.getReference()));
    assert UnversionedStrTestEntity.class.equals(HibernateProxyHelper.getClassWithoutInitializingProxy(rev1.getReference()));
    assert UnversionedStrTestEntity.class.equals(Hibernate.getClass(rev1.getReference()));
}
Also used : UnversionedStrTestEntity(org.hibernate.envers.test.entities.UnversionedStrTestEntity) HibernateProxy(org.hibernate.proxy.HibernateProxy) TargetNotAuditedEntity(org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAuditedEntity) Test(org.junit.Test)

Example 8 with UnversionedStrTestEntity

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

the class ManyToOneIdNotAudited method initData.

@Test
@Priority(10)
public void initData() {
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    UnversionedStrTestEntity uste = new UnversionedStrTestEntity();
    uste.setStr("test1");
    em.persist(uste);
    id1 = new ManyToOneNotAuditedEmbId(uste);
    em.getTransaction().commit();
    // Revision 2
    em = getEntityManager();
    em.getTransaction().begin();
    ManyToOneIdNotAuditedTestEntity mtoinate = new ManyToOneIdNotAuditedTestEntity();
    mtoinate.setData("data1");
    mtoinate.setId(id1);
    em.persist(mtoinate);
    em.getTransaction().commit();
}
Also used : EntityManager(javax.persistence.EntityManager) ManyToOneIdNotAuditedTestEntity(org.hibernate.envers.test.entities.ids.ManyToOneIdNotAuditedTestEntity) ManyToOneNotAuditedEmbId(org.hibernate.envers.test.entities.ids.ManyToOneNotAuditedEmbId) UnversionedStrTestEntity(org.hibernate.envers.test.entities.UnversionedStrTestEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 9 with UnversionedStrTestEntity

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

the class RemovedObjectQueryTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    SetRefEdEntity refEdEntity1 = new SetRefEdEntity(1, "Demo Data 1");
    SetRefIngEntity refIngEntity1 = new SetRefIngEntity(2, "Example Data 1", refEdEntity1);
    // Revision 1
    em.getTransaction().begin();
    em.persist(refEdEntity1);
    em.persist(refIngEntity1);
    em.getTransaction().commit();
    // Revision 2 - removing both object in the same revision
    em.getTransaction().begin();
    refEdEntity1 = em.find(SetRefEdEntity.class, 1);
    refIngEntity1 = em.find(SetRefIngEntity.class, 2);
    em.remove(refIngEntity1);
    em.remove(refEdEntity1);
    em.getTransaction().commit();
    SetRefEdEntity refEdEntity2 = new SetRefEdEntity(3, "Demo Data 2");
    SetRefIngEntity refIngEntity2 = new SetRefIngEntity(4, "Example Data 2", refEdEntity2);
    // Revision 3
    em.getTransaction().begin();
    em.persist(refEdEntity2);
    em.persist(refIngEntity2);
    em.getTransaction().commit();
    // Revision 4 - removing child object
    em.getTransaction().begin();
    refIngEntity2 = em.find(SetRefIngEntity.class, 4);
    em.remove(refIngEntity2);
    em.getTransaction().commit();
    // Revision 5 - removing parent object
    em.getTransaction().begin();
    refEdEntity2 = em.find(SetRefEdEntity.class, 3);
    em.remove(refEdEntity2);
    em.getTransaction().commit();
    SetOwningEntity setOwningEntity1 = new SetOwningEntity(5, "Demo Data 1");
    SetOwnedEntity setOwnedEntity1 = new SetOwnedEntity(6, "Example Data 1");
    Set<SetOwningEntity> owning = new HashSet<SetOwningEntity>();
    Set<SetOwnedEntity> owned = new HashSet<SetOwnedEntity>();
    owning.add(setOwningEntity1);
    owned.add(setOwnedEntity1);
    setOwningEntity1.setReferences(owned);
    setOwnedEntity1.setReferencing(owning);
    // Revision 6
    em.getTransaction().begin();
    em.persist(setOwnedEntity1);
    em.persist(setOwningEntity1);
    em.getTransaction().commit();
    // Revision 7 - removing both object in the same revision
    em.getTransaction().begin();
    setOwnedEntity1 = em.find(SetOwnedEntity.class, 6);
    setOwningEntity1 = em.find(SetOwningEntity.class, 5);
    em.remove(setOwningEntity1);
    em.remove(setOwnedEntity1);
    em.getTransaction().commit();
    SetOwningEntity setOwningEntity2 = new SetOwningEntity(7, "Demo Data 2");
    SetOwnedEntity setOwnedEntity2 = new SetOwnedEntity(8, "Example Data 2");
    owning = new HashSet<SetOwningEntity>();
    owned = new HashSet<SetOwnedEntity>();
    owning.add(setOwningEntity2);
    owned.add(setOwnedEntity2);
    setOwningEntity2.setReferences(owned);
    setOwnedEntity2.setReferencing(owning);
    // Revision 8
    em.getTransaction().begin();
    em.persist(setOwnedEntity2);
    em.persist(setOwningEntity2);
    em.getTransaction().commit();
    // Revision 9 - removing first object
    em.getTransaction().begin();
    setOwningEntity2 = em.find(SetOwningEntity.class, 7);
    em.remove(setOwningEntity2);
    em.getTransaction().commit();
    // Revision 10 - removing second object
    em.getTransaction().begin();
    setOwnedEntity2 = em.find(SetOwnedEntity.class, 8);
    em.remove(setOwnedEntity2);
    em.getTransaction().commit();
    StringSetEntity stringSetEntity = new StringSetEntity();
    stringSetEntity.getStrings().add("string 1");
    stringSetEntity.getStrings().add("string 2");
    // Revision 11
    em.getTransaction().begin();
    em.persist(stringSetEntity);
    em.getTransaction().commit();
    stringSetId = stringSetEntity.getId();
    // Revision 12 - removing element collection
    em.getTransaction().begin();
    stringSetEntity = em.find(StringSetEntity.class, stringSetEntity.getId());
    em.remove(stringSetEntity);
    em.getTransaction().commit();
    // Revision 13
    em.getTransaction().begin();
    unversionedEntity1 = new UnversionedStrTestEntity("string 1");
    unversionedEntity2 = new UnversionedStrTestEntity("string 2");
    M2MIndexedListTargetNotAuditedEntity relationNotAuditedEntity = new M2MIndexedListTargetNotAuditedEntity(1, "Parent");
    relationNotAuditedEntity.getReferences().add(unversionedEntity1);
    relationNotAuditedEntity.getReferences().add(unversionedEntity2);
    em.persist(unversionedEntity1);
    em.persist(unversionedEntity2);
    em.persist(relationNotAuditedEntity);
    em.getTransaction().commit();
    // Revision 14 - removing entity with unversioned relation
    em.getTransaction().begin();
    relationNotAuditedEntity = em.find(M2MIndexedListTargetNotAuditedEntity.class, relationNotAuditedEntity.getId());
    em.remove(relationNotAuditedEntity);
    em.getTransaction().commit();
    stringEntity1 = new StrTestPrivSeqEntity("Value 1");
    stringEntity2 = new StrTestPrivSeqEntity("Value 2");
    intEntity1 = new IntTestPrivSeqEntity(1);
    intEntity2 = new IntTestPrivSeqEntity(2);
    TernaryMapEntity mapEntity = new TernaryMapEntity();
    mapEntity.getMap().put(intEntity1, stringEntity1);
    mapEntity.getMap().put(intEntity2, stringEntity2);
    // Revision 15
    em.getTransaction().begin();
    em.persist(stringEntity1);
    em.persist(stringEntity2);
    em.persist(intEntity1);
    em.persist(intEntity2);
    em.persist(mapEntity);
    em.getTransaction().commit();
    ternaryMapId = mapEntity.getId();
    // Revision 16 - updating ternary map
    em.getTransaction().begin();
    intEntity2 = em.find(IntTestPrivSeqEntity.class, intEntity2.getId());
    intEntity2.setNumber(3);
    intEntity2 = em.merge(intEntity2);
    stringEntity2 = em.find(StrTestPrivSeqEntity.class, stringEntity2.getId());
    stringEntity2.setStr("Value 3");
    stringEntity2 = em.merge(stringEntity2);
    em.getTransaction().commit();
    // Revision 17 - removing ternary map
    em.getTransaction().begin();
    mapEntity = em.find(TernaryMapEntity.class, mapEntity.getId());
    em.remove(mapEntity);
    em.getTransaction().commit();
    CollectionRefEdEntity collEd1 = new CollectionRefEdEntity(1, "data_ed_1");
    CollectionRefIngEntity collIng1 = new CollectionRefIngEntity(2, "data_ing_1", collEd1);
    collEd1.setReffering(new ArrayList<CollectionRefIngEntity>());
    collEd1.getReffering().add(collIng1);
    // Revision 18 - testing one-to-many collection
    em.getTransaction().begin();
    em.persist(collEd1);
    em.persist(collIng1);
    em.getTransaction().commit();
    // Revision 19
    em.getTransaction().begin();
    collIng1 = em.find(CollectionRefIngEntity.class, collIng1.getId());
    collIng1.setData("modified data_ing_1");
    collIng1 = em.merge(collIng1);
    em.getTransaction().commit();
    // Revision 20
    em.getTransaction().begin();
    collEd1 = em.find(CollectionRefEdEntity.class, collEd1.getId());
    collIng1 = em.find(CollectionRefIngEntity.class, collIng1.getId());
    em.remove(collIng1);
    em.remove(collEd1);
    em.getTransaction().commit();
    ListOwnedEntity listEd1 = new ListOwnedEntity(1, "data_ed_1");
    ListOwningEntity listIng1 = new ListOwningEntity(2, "data_ing_1");
    listEd1.setReferencing(new ArrayList<ListOwningEntity>());
    listIng1.setReferences(new ArrayList<ListOwnedEntity>());
    listEd1.getReferencing().add(listIng1);
    listIng1.getReferences().add(listEd1);
    // Revision 21 - testing many-to-many collection
    em.getTransaction().begin();
    em.persist(listEd1);
    em.persist(listIng1);
    em.getTransaction().commit();
    // Revision 22
    em.getTransaction().begin();
    listIng1 = em.find(ListOwningEntity.class, listIng1.getId());
    listIng1.setData("modified data_ing_1");
    listIng1 = em.merge(listIng1);
    em.getTransaction().commit();
    // Revision 23
    em.getTransaction().begin();
    listIng1 = em.find(ListOwningEntity.class, listIng1.getId());
    listEd1 = em.find(ListOwnedEntity.class, listEd1.getId());
    em.remove(listIng1);
    em.remove(listEd1);
    em.getTransaction().commit();
    em.close();
}
Also used : TernaryMapEntity(org.hibernate.envers.test.integration.manytomany.ternary.TernaryMapEntity) SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) CollectionRefIngEntity(org.hibernate.envers.test.entities.onetomany.CollectionRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) ListOwningEntity(org.hibernate.envers.test.entities.manytomany.ListOwningEntity) SetOwningEntity(org.hibernate.envers.test.entities.manytomany.SetOwningEntity) StrTestPrivSeqEntity(org.hibernate.envers.test.entities.StrTestPrivSeqEntity) CollectionRefEdEntity(org.hibernate.envers.test.entities.onetomany.CollectionRefEdEntity) EntityManager(javax.persistence.EntityManager) StringSetEntity(org.hibernate.envers.test.entities.collection.StringSetEntity) M2MIndexedListTargetNotAuditedEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.M2MIndexedListTargetNotAuditedEntity) ListOwnedEntity(org.hibernate.envers.test.entities.manytomany.ListOwnedEntity) SetOwnedEntity(org.hibernate.envers.test.entities.manytomany.SetOwnedEntity) UnversionedStrTestEntity(org.hibernate.envers.test.entities.UnversionedStrTestEntity) IntTestPrivSeqEntity(org.hibernate.envers.test.entities.IntTestPrivSeqEntity) HashSet(java.util.HashSet) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 10 with UnversionedStrTestEntity

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

the class ProxyIdentifier 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());
    tnae1 = new TargetNotAuditedEntity(1, "tnae1", uste1);
    em.persist(tnae1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId());
    mtonane1 = new ManyToOneNotAuditedNullEntity(2, "mtonane1", uste2);
    mtmnane1 = new ManyToManyNotAuditedNullEntity(3, "mtmnane1");
    mtmnane1.getReferences().add(uste2);
    otmnane1 = new OneToManyNotAuditedNullEntity(4, "otmnane1");
    otmnane1.getReferences().add(uste2);
    emtonane1 = new ExtManyToOneNotAuditedNullEntity(5, "emtonane1", uste2, "extension");
    em.persist(mtonane1);
    em.persist(mtmnane1);
    em.persist(otmnane1);
    em.persist(emtonane1);
    em.getTransaction().commit();
    em.clear();
    // Revision 3
    // Remove not audited target entity, so we can verify null reference
    // when @NotFound(action = NotFoundAction.IGNORE) applied.
    em.getTransaction().begin();
    ManyToOneNotAuditedNullEntity tmp1 = em.find(ManyToOneNotAuditedNullEntity.class, mtonane1.getId());
    tmp1.setReference(null);
    tmp1 = em.merge(tmp1);
    ManyToManyNotAuditedNullEntity tmp2 = em.find(ManyToManyNotAuditedNullEntity.class, mtmnane1.getId());
    tmp2.setReferences(null);
    tmp2 = em.merge(tmp2);
    OneToManyNotAuditedNullEntity tmp3 = em.find(OneToManyNotAuditedNullEntity.class, otmnane1.getId());
    tmp3.setReferences(null);
    tmp3 = em.merge(tmp3);
    ExtManyToOneNotAuditedNullEntity tmp4 = em.find(ExtManyToOneNotAuditedNullEntity.class, emtonane1.getId());
    tmp4.setReference(null);
    tmp4 = em.merge(tmp4);
    em.remove(em.getReference(UnversionedStrTestEntity.class, uste2.getId()));
    em.getTransaction().commit();
    em.close();
}
Also used : EntityManager(javax.persistence.EntityManager) OneToManyNotAuditedNullEntity(org.hibernate.envers.test.entities.onetomany.OneToManyNotAuditedNullEntity) UnversionedStrTestEntity(org.hibernate.envers.test.entities.UnversionedStrTestEntity) ManyToOneNotAuditedNullEntity(org.hibernate.envers.test.entities.manytoone.unidirectional.ManyToOneNotAuditedNullEntity) ExtManyToOneNotAuditedNullEntity(org.hibernate.envers.test.entities.manytoone.unidirectional.ExtManyToOneNotAuditedNullEntity) ExtManyToOneNotAuditedNullEntity(org.hibernate.envers.test.entities.manytoone.unidirectional.ExtManyToOneNotAuditedNullEntity) TargetNotAuditedEntity(org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAuditedEntity) ManyToManyNotAuditedNullEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.ManyToManyNotAuditedNullEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

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