use of javax.persistence.NoResultException in project spring-framework by spring-projects.
the class AbstractContainerEntityManagerFactoryIntegrationTests method testQueryNoPersons.
@Test
@SuppressWarnings("unchecked")
public void testQueryNoPersons() {
EntityManager em = entityManagerFactory.createEntityManager();
Query q = em.createQuery("select p from Person as p");
List<Person> people = q.getResultList();
assertEquals(0, people.size());
try {
assertNull(q.getSingleResult());
fail("Should have thrown NoResultException");
} catch (NoResultException ex) {
// expected
}
}
use of javax.persistence.NoResultException in project spring-framework by spring-projects.
the class AbstractContainerEntityManagerFactoryIntegrationTests method testQueryNoPersonsShared.
@Test
@SuppressWarnings({ "unused", "unchecked" })
public void testQueryNoPersonsShared() {
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
Query q = em.createQuery("select p from Person as p");
q.setFlushMode(FlushModeType.AUTO);
List<Person> people = q.getResultList();
try {
assertNull(q.getSingleResult());
fail("Should have thrown NoResultException");
} catch (NoResultException ex) {
// expected
}
}
use of javax.persistence.NoResultException in project spring-framework by spring-projects.
the class AbstractContainerEntityManagerFactoryIntegrationTests method testQueryNoPersonsSharedNotTransactional.
@Test
@SuppressWarnings("unchecked")
public void testQueryNoPersonsSharedNotTransactional() {
endTransaction();
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(entityManagerFactory);
Query q = em.createQuery("select p from Person as p");
q.setFlushMode(FlushModeType.AUTO);
List<Person> people = q.getResultList();
assertEquals(0, people.size());
try {
assertNull(q.getSingleResult());
fail("Should have thrown IllegalStateException");
} catch (Exception ex) {
// We would typically expect an IllegalStateException, but Hibernate throws a
// PersistenceException. So we assert the contents of the exception message instead.
assertTrue(ex.getMessage().contains("closed"));
}
q = em.createQuery("select p from Person as p");
q.setFlushMode(FlushModeType.AUTO);
try {
assertNull(q.getSingleResult());
fail("Should have thrown NoResultException");
} catch (NoResultException ex) {
// expected
}
}
use of javax.persistence.NoResultException in project spring-framework by spring-projects.
the class AbstractContainerEntityManagerFactoryIntegrationTests method testQueryNoPersonsNotTransactional.
@Test
@SuppressWarnings("unchecked")
public void testQueryNoPersonsNotTransactional() {
EntityManager em = entityManagerFactory.createEntityManager();
Query q = em.createQuery("select p from Person as p");
List<Person> people = q.getResultList();
assertEquals(0, people.size());
try {
assertNull(q.getSingleResult());
fail("Should have thrown NoResultException");
} catch (NoResultException ex) {
// expected
}
}
use of javax.persistence.NoResultException in project webpieces by deanhiller.
the class UserTestDbo method findWithJoin.
public static UserTestDbo findWithJoin(EntityManager mgr, int id) {
Query query = mgr.createNamedQuery("findByIdWithRoleJoin");
query.setParameter("id", id);
try {
return (UserTestDbo) query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
Aggregations