You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2016/12/03 16:37:43 UTC

[17/50] tomee git commit: trying to suspend the tx in progress if there when the emf is lazily created to avoid issues with our managed connections

trying to suspend the tx in progress if there when the emf is lazily created to avoid issues with our managed connections


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/78b76fca
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/78b76fca
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/78b76fca

Branch: refs/heads/tomee-1.7.x
Commit: 78b76fcaea62d78d19f9416bd361dc4346f40cc2
Parents: 9f14c06
Author: rmannibucau <rm...@apache.org>
Authored: Mon Oct 3 17:30:16 2016 +0200
Committer: rmannibucau <rm...@apache.org>
Committed: Mon Oct 3 17:30:16 2016 +0200

----------------------------------------------------------------------
 .../classic/EntityManagerFactoryCallable.java     | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/78b76fca/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EntityManagerFactoryCallable.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EntityManagerFactoryCallable.java b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EntityManagerFactoryCallable.java
index 854c9c4..6ef05e9 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EntityManagerFactoryCallable.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EntityManagerFactoryCallable.java
@@ -17,6 +17,7 @@
 
 package org.apache.openejb.assembler.classic;
 
+import org.apache.openejb.OpenEJB;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.persistence.PersistenceUnitInfoImpl;
 import org.apache.openejb.util.LogCategory;
@@ -28,6 +29,7 @@ import javax.enterprise.inject.spi.BeanManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.ValidationMode;
 import javax.persistence.spi.PersistenceProvider;
+import javax.transaction.Transaction;
 import javax.validation.ValidatorFactory;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
@@ -108,7 +110,21 @@ public class EntityManagerFactoryCallable implements Callable<EntityManagerFacto
 
             customizeProperties(properties);
 
-            final EntityManagerFactory emf = persistenceProvider.createContainerEntityManagerFactory(unitInfo, properties);
+            // ensure no tx is there cause a managed connection would fail if the provider setAutocCommit(true) and some hib* have this good idea
+            final Transaction transaction;
+            if (unitInfo.isLazilyInitialized()) {
+                transaction = OpenEJB.getTransactionManager().suspend();
+            } else {
+                transaction = null;
+            }
+            final EntityManagerFactory emf;
+            try {
+                emf = persistenceProvider.createContainerEntityManagerFactory(unitInfo, properties);
+            } finally {
+                if (unitInfo.isLazilyInitialized() && transaction != null) {
+                    OpenEJB.getTransactionManager().resume(transaction);
+                }
+            }
 
             if (unitInfo.getProperties() != null
                     && "true".equalsIgnoreCase(unitInfo.getProperties().getProperty(OPENEJB_JPA_INIT_ENTITYMANAGER))