use of javax.persistence.EntityManager in project hibernate-orm by hibernate.
the class MultiCircleJpaCascadeTest method testMerge.
@Test
public void testMerge() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
b = em.merge(b);
c = b.getC();
d = b.getD();
e = d.getE();
f = e.getF();
g = f.getG();
em.getTransaction().commit();
em.close();
check();
}
use of javax.persistence.EntityManager in project hibernate-orm by hibernate.
the class MultiCircleJpaCascadeTest method testPersistThenUpdate.
@Test
@FailureExpected(jiraKey = "HHH-6999")
public // fails on d.e; should pass
void testPersistThenUpdate() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist(b);
// remove old e from associations
e.getDCollection().remove(d);
d.setE(null);
f.getECollection().remove(e);
e.setF(null);
// add new e to associations
e = new E();
e.getDCollection().add(d);
f.getECollection().add(e);
d.setE(e);
e.setF(f);
em.getTransaction().commit();
em.close();
check();
}
use of javax.persistence.EntityManager in project hibernate-orm by hibernate.
the class MultiCircleJpaCascadeTest method testPersistThenUpdateNoCascadeToTransient.
@Test
public void testPersistThenUpdateNoCascadeToTransient() {
// expected to fail, so nothing will be persisted.
skipCleanup = true;
// remove elements from collections and persist
c.getBCollection().clear();
c.getDCollection().clear();
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist(c);
// now add the elements back
c.getBCollection().add(b);
c.getDCollection().add(d);
try {
em.getTransaction().commit();
fail("should have thrown IllegalStateException");
} catch (RollbackException ex) {
assertTrue(ex.getCause() instanceof IllegalStateException);
IllegalStateException ise = (IllegalStateException) ex.getCause();
// should fail on entity g (due to no cascade to f.g);
// instead it fails on entity e ( due to no cascade to d.e)
// because e is not in the process of being saved yet.
// when HHH-6999 is fixed, this test should be changed to
// check for g and f.g
//noinspection ThrowableResultOfMethodCallIgnored
TransientPropertyValueException tpve = assertTyping(TransientPropertyValueException.class, ise.getCause());
assertEquals(E.class.getName(), tpve.getTransientEntityName());
assertEquals(D.class.getName(), tpve.getPropertyOwnerEntityName());
assertEquals("e", tpve.getPropertyName());
}
em.close();
}
use of javax.persistence.EntityManager in project hibernate-orm by hibernate.
the class MultiCircleJpaCascadeTest method testPersist.
@Test
public void testPersist() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist(b);
em.getTransaction().commit();
em.close();
check();
}
use of javax.persistence.EntityManager in project hibernate-orm by hibernate.
the class ExpressionsTest method testEmptyConjunctionIsFalse.
@Test
public void testEmptyConjunctionIsFalse() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
CriteriaQuery<Product> criteria = builder.createQuery(Product.class);
criteria.from(Product.class);
criteria.where(builder.isFalse(builder.and()));
List<Product> result = em.createQuery(criteria).getResultList();
assertEquals(0, result.size());
em.getTransaction().commit();
em.close();
}
Aggregations