Search in sources :

Example 46 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 47 with StrTestEntity

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

the class EmptyStringTest method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    // Revision 1
    em.getTransaction().begin();
    StrTestEntity emptyEntity = new StrTestEntity("");
    em.persist(emptyEntity);
    StrTestEntity nullEntity = new StrTestEntity(null);
    em.persist(nullEntity);
    em.getTransaction().commit();
    emptyId = emptyEntity.getId();
    nullId = nullEntity.getId();
    em.close();
    em = getEntityManager();
    // Should not generate revision after NULL to "" modification and vice versa on Oracle.
    em.getTransaction().begin();
    emptyEntity = em.find(StrTestEntity.class, emptyId);
    emptyEntity.setStr(null);
    em.merge(emptyEntity);
    nullEntity = em.find(StrTestEntity.class, nullId);
    nullEntity.setStr("");
    em.merge(nullEntity);
    em.getTransaction().commit();
    em.close();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 48 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 49 with StrTestEntity

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

the class BasicUniMap method initData.

@Test
@Priority(10)
public void initData() {
    EntityManager em = getEntityManager();
    StrTestEntity str1 = new StrTestEntity("str1");
    StrTestEntity str2 = new StrTestEntity("str2");
    MapUniEntity coll1 = new MapUniEntity(3, "coll1");
    // Revision 1 (coll1: initialy one mapping)
    em.getTransaction().begin();
    em.persist(str1);
    em.persist(str2);
    coll1.setMap(new HashMap<String, StrTestEntity>());
    coll1.getMap().put("1", str1);
    em.persist(coll1);
    em.getTransaction().commit();
    // Revision 2 (coll1: adding one mapping)
    em.getTransaction().begin();
    str2 = em.find(StrTestEntity.class, str2.getId());
    coll1 = em.find(MapUniEntity.class, coll1.getId());
    coll1.getMap().put("2", str2);
    em.getTransaction().commit();
    // Revision 3 (coll1: replacing one mapping)
    em.getTransaction().begin();
    str1 = em.find(StrTestEntity.class, str1.getId());
    coll1 = em.find(MapUniEntity.class, coll1.getId());
    coll1.getMap().put("2", str1);
    em.getTransaction().commit();
    // Revision 4 (coll1: removing one mapping)
    em.getTransaction().begin();
    coll1 = em.find(MapUniEntity.class, coll1.getId());
    coll1.getMap().remove("1");
    em.getTransaction().commit();
    // 
    str1_id = str1.getId();
    str2_id = str2.getId();
    coll1_id = coll1.getId();
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) MapUniEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.MapUniEntity) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Example 50 with StrTestEntity

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

the class JtaExceptionListener method testTransactionRollback.

@Test(expected = RollbackException.class)
// must run before testDataNotPersisted()
@Priority(5)
public void testTransactionRollback() throws Exception {
    TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
    try {
        EntityManager em = getEntityManager();
        // Trying to persist an entity - however the listener should throw an exception, so the entity
        // shouldn't be persisted
        StrTestEntity te = new StrTestEntity("x");
        em.persist(te);
    } finally {
        TestingJtaPlatformImpl.tryCommit();
    }
}
Also used : StrTestEntity(org.hibernate.envers.test.entities.StrTestEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) Priority(org.hibernate.envers.test.Priority)

Aggregations

StrTestEntity (org.hibernate.envers.test.entities.StrTestEntity)103 Test (org.junit.Test)99 EntityManager (javax.persistence.EntityManager)51 Priority (org.hibernate.envers.test.Priority)48 Session (org.hibernate.Session)8 StrIntTestEntity (org.hibernate.envers.test.entities.StrIntTestEntity)8 TestForIssue (org.hibernate.testing.TestForIssue)5 ListRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.ListRefCollEntity)4 SetRefCollEntity (org.hibernate.envers.test.entities.onetomany.detached.SetRefCollEntity)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