Search in sources :

Example 11 with StrTestEntity

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

the class HasChangedIdMapKey method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    IdMapKeyEntity imke = new IdMapKeyEntity();
    // Revision 1 (intialy 1 mapping)
    em.getTransaction().begin();
    StrTestEntity ste1 = new StrTestEntity("x");
    StrTestEntity ste2 = new StrTestEntity("y");
    em.persist(ste1);
    em.persist(ste2);
    imke.getIdmap().put(ste1.getId(), ste1);
    em.persist(imke);
    em.getTransaction().commit();
    // Revision 2 (sse1: adding 1 mapping)
    em.getTransaction().begin();
    ste2 = em.find(StrTestEntity.class, ste2.getId());
    imke = em.find(IdMapKeyEntity.class, imke.getId());
    imke.getIdmap().put(ste2.getId(), ste2);
    em.getTransaction().commit();
    //
    imke_id = imke.getId();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) IdMapKeyEntity(org.hibernate.envers.test.integration.collection.mapkey.IdMapKeyEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 12 with StrTestEntity

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

the class HasChangedManyToOneInComponent method initData.

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

Example 13 with StrTestEntity

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

the class OneToManyUnidirectionalNaming method initData.

@Test
@Priority(10)
public void initData() {
    DetachedNamingTestEntity uni1 = new DetachedNamingTestEntity(1, "data1");
    StrTestEntity str1 = new StrTestEntity("str1");
    // Revision 1
    EntityManager em = getEntityManager();
    em.getTransaction().begin();
    uni1.setCollection(new HashSet<StrTestEntity>());
    em.persist(uni1);
    em.persist(str1);
    em.getTransaction().commit();
    // Revision 2
    em.getTransaction().begin();
    uni1 = em.find(DetachedNamingTestEntity.class, uni1.getId());
    str1 = em.find(StrTestEntity.class, str1.getId());
    uni1.getCollection().add(str1);
    em.getTransaction().commit();
    //
    uni1_id = uni1.getId();
    str1_id = str1.getId();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 14 with StrTestEntity

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

the class OneToManyUnidirectionalNaming method testHistoryOfUniId1.

@Test
public void testHistoryOfUniId1() {
    StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
    DetachedNamingTestEntity rev1 = getAuditReader().find(DetachedNamingTestEntity.class, uni1_id, 1);
    DetachedNamingTestEntity rev2 = getAuditReader().find(DetachedNamingTestEntity.class, uni1_id, 2);
    assert rev1.getCollection().equals(TestTools.makeSet());
    assert rev2.getCollection().equals(TestTools.makeSet(str1));
    assert "data1".equals(rev1.getData());
    assert "data1".equals(rev2.getData());
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Example 15 with StrTestEntity

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

the class VersionsJoinTableNaming method testHistoryOfUniId1.

@Test
public void testHistoryOfUniId1() {
    StrTestEntity str1 = getEntityManager().find(StrTestEntity.class, str1_id);
    VersionsJoinTableTestEntity rev1 = getAuditReader().find(VersionsJoinTableTestEntity.class, uni1_id, 1);
    VersionsJoinTableTestEntity rev2 = getAuditReader().find(VersionsJoinTableTestEntity.class, uni1_id, 2);
    assert rev1.getCollection().equals(TestTools.makeSet());
    assert rev2.getCollection().equals(TestTools.makeSet(str1));
    assert "data1".equals(rev1.getData());
    assert "data1".equals(rev2.getData());
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) Test(org.junit.Test)

Aggregations

StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)102 Test (org.junit.Test)98 EntityManager (javax.persistence.EntityManager)50 Priority (org.hibernate.envers.test.Priority)48 Session (org.hibernate.Session)8 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)8 ListRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity)4 SetRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity)4 TestForIssue (org.hibernate.testing.TestForIssue)4 ManyToOneComponent (org.hibernate.envers.test.entities.components.relations.ManyToOneComponent)3 ManyToOneComponentTestEntity (org.hibernate.envers.test.entities.components.relations.ManyToOneComponentTestEntity)3 OneToManyComponent (org.hibernate.envers.test.entities.components.relations.OneToManyComponent)3 OneToManyComponentTestEntity (org.hibernate.envers.test.entities.components.relations.OneToManyComponentTestEntity)3 SortedSetEntity (org.hibernate.envers.test.entities.manytomany.SortedSetEntity)3 ListUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.ListUniEntity)3 SetUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.SetUniEntity)3 List (java.util.List)2 RevisionType (org.hibernate.envers.RevisionType)2 JoinTableEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.JoinTableEntity)2 MapUniEntity (org.hibernate.envers.test.entities.manytomany.unidirectional.MapUniEntity)2