From e12fbd3e2b9ee031913003a0eb4022cfcb71c247 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 8 Jun 2010 11:06:02 +0000 Subject: [PATCH] avoid EntityManager close() exception through isOpen() check (SPR-7215) --- .../orm/jpa/support/PersistenceInjectionTests.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/org.springframework.orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java b/org.springframework.orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java index 7f40fb0db9..7d3b3a24b0 100644 --- a/org.springframework.orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java +++ b/org.springframework.orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java @@ -573,6 +573,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT EntityManager em = (EntityManager) emC.getMock(); emfMc.expectAndReturn(mockEmf.createEntityManager(props), em); emC.expectAndReturn(em.getDelegate(), new Object()); + emC.expectAndReturn(em.isOpen(), true); em.close(); emfMc.replay(); @@ -602,6 +603,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT // only one call made - the first EM definition wins (in this case the one w/ the properties) emfMc.expectAndReturn(mockEmf.createEntityManager(props), em); emC.expectAndReturn(em.getDelegate(), new Object(), 2); + emC.expectAndReturn(em.isOpen(), true); em.close(); emfMc.replay(); @@ -639,6 +641,7 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT // only one call made - the first EM definition wins (in this case the one w/o the properties) emfMc.expectAndReturn(mockEmf.createEntityManager(), em); emC.expectAndReturn(em.getDelegate(), new Object(), 2); + emC.expectAndReturn(em.isOpen(), true); em.close(); emfMc.replay(); @@ -832,6 +835,9 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT public static boolean closed; public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if ("isOpen".equals(method.getName())) { + return true; + } if ("close".equals(method.getName())) { closed = true; return null;