use of org.springframework.orm.jpa.domain.Person 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 org.springframework.orm.jpa.domain.Person in project spring-framework by spring-projects.
the class AbstractContainerEntityManagerFactoryIntegrationTests method testEntityManagerProxyIsProxy.
@Test
@SuppressWarnings({ "unused", "unchecked" })
public void testEntityManagerProxyIsProxy() {
assertTrue(Proxy.isProxyClass(sharedEntityManager.getClass()));
Query q = sharedEntityManager.createQuery("select p from Person as p");
List<Person> people = q.getResultList();
assertTrue("Should be open to start with", sharedEntityManager.isOpen());
sharedEntityManager.close();
assertTrue("Close should have been silently ignored", sharedEntityManager.isOpen());
}
use of org.springframework.orm.jpa.domain.Person in project spring-framework by spring-projects.
the class ApplicationManagedEntityManagerIntegrationTests method doInstantiateAndSave.
protected void doInstantiateAndSave(EntityManager em) {
testStateClean();
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 ApplicationManagedEntityManagerIntegrationTests method testEntityManagerProxyIsProxy.
@Test
@SuppressWarnings("unchecked")
public void testEntityManagerProxyIsProxy() {
EntityManager em = entityManagerFactory.createEntityManager();
assertTrue(Proxy.isProxyClass(em.getClass()));
Query q = em.createQuery("select p from Person as p");
List<Person> people = q.getResultList();
assertNotNull(people);
assertTrue("Should be open to start with", em.isOpen());
em.close();
assertFalse("Close should work on application managed EM", em.isOpen());
}
use of org.springframework.orm.jpa.domain.Person in project spring-framework by spring-projects.
the class ContainerManagedEntityManagerIntegrationTests method testReuseInNewTransaction.
@Test
public void testReuseInNewTransaction() {
EntityManager em = createContainerManagedEntityManager();
doInstantiateAndSave(em);
endTransaction();
//assertFalse(em.getTransaction().isActive());
startNewTransaction();
// Call any method: should cause automatic tx invocation
assertFalse(em.contains(new Person()));
//assertTrue(em.getTransaction().isActive());
doInstantiateAndSave(em);
setComplete();
// Should rollback
endTransaction();
assertEquals("Tx must have committed back", 1, countRowsInTable(em, "person"));
// Now clean up the database
deleteFromTables("person");
}
Aggregations