tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject 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
Date Mon, 03 Oct 2016 15:30:22 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 9f14c0610 -> 78b76fcae


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/master
Commit: 78b76fcaea62d78d19f9416bd361dc4346f40cc2
Parents: 9f14c06
Author: rmannibucau <rmannibucau@apache.org>
Authored: Mon Oct 3 17:30:16 2016 +0200
Committer: rmannibucau <rmannibucau@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))


Mime
View raw message