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();
}
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();
}
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();
}
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();
}
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();
}
}
Aggregations