use of org.springframework.orm.jpa.domain.Person 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 org.springframework.orm.jpa.domain.Person in project spring-framework by spring-projects.
the class AbstractContainerEntityManagerFactoryIntegrationTests method testMultipleResults.
@Test
@SuppressWarnings("unchecked")
public void testMultipleResults() {
// Add with JDBC
String firstName = "Tony";
insertPerson(firstName);
assertTrue(Proxy.isProxyClass(sharedEntityManager.getClass()));
Query q = sharedEntityManager.createQuery("select p from Person as p");
List<Person> people = q.getResultList();
assertEquals(1, people.size());
assertEquals(firstName, people.get(0).getFirstName());
}
use of org.springframework.orm.jpa.domain.Person 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 org.springframework.orm.jpa.domain.Person in project spring-framework by spring-projects.
the class ContainerManagedEntityManagerIntegrationTests method doInstantiateAndSave.
protected void doInstantiateAndSave(EntityManager em) {
assertEquals("Should be no people from previous transactions", 0, countRowsInTable(em, "person"));
Person p = new Person();
p.setFirstName("Tony");
p.setLastName("Blair");
em.persist(p);
em.flush();
assertEquals("1 row must have been inserted", 1, countRowsInTable(em, "person"));
}
use of org.springframework.orm.jpa.domain.Person 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
}
}
Aggregations