From f54a3aba7368edf5d2f78d9f81f7de7e119058cd Mon Sep 17 00:00:00 2001 From: erik Date: Wed, 21 Jul 2010 08:10:02 +0000 Subject: [PATCH] --- .../wamblee/test/persistence/JpaBuilder.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/test/enterprise/src/main/java/org/wamblee/test/persistence/JpaBuilder.java b/test/enterprise/src/main/java/org/wamblee/test/persistence/JpaBuilder.java index dbc88dc0..dac2789b 100644 --- a/test/enterprise/src/main/java/org/wamblee/test/persistence/JpaBuilder.java +++ b/test/enterprise/src/main/java/org/wamblee/test/persistence/JpaBuilder.java @@ -66,8 +66,8 @@ public class JpaBuilder implements TransactionResource { private String user; private String password; private EntityManagerFactory factory; - private ThreadSpecificProxyFactory entityManager; - + private ThreadSpecificProxyFactory entityManager; + /** * Constructs the builder. * @@ -86,7 +86,8 @@ public class JpaBuilder implements TransactionResource { url = aUrl; user = aUser; password = aPassword; - entityManager = new ThreadSpecificProxyFactory(EntityManager.class); + entityManager = new ThreadSpecificProxyFactory( + EntityManager.class); } /** @@ -163,7 +164,7 @@ public class JpaBuilder implements TransactionResource { LOGGER.log(Level.WARNING, "Exception occured", e); rollback(em); throw e; - } + } } @Override @@ -188,19 +189,25 @@ public class JpaBuilder implements TransactionResource { @Override public void rollback(EntityManager aEntityManager) { try { - aEntityManager.getTransaction().rollback(); + EntityTransaction transaction = aEntityManager.getTransaction(); + if (transaction.isActive()) { + transaction.rollback(); + } } finally { - aEntityManager.close(); + if (aEntityManager.isOpen()) { + aEntityManager.close(); + } entityManager.set(null); } } - + /** - * Gets a contextual reference to an entity manager that delegates to the - * appropriate (current) one which is active for the current transaction. - * @return EntityManager. + * Gets a contextual reference to an entity manager that delegates to the + * appropriate (current) one which is active for the current transaction. + * + * @return EntityManager. */ - public EntityManager getContextualEntityManager() { - return entityManager.getProxy(); + public EntityManager getContextualEntityManager() { + return entityManager.getProxy(); } } -- 2.31.1