camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/3] camel git commit: CAMEL-9608 camel-jpa consumer fails to poll after transaction timeout
Date Wed, 17 Feb 2016 08:14:27 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x bdbfc1783 -> b72718912
  refs/heads/camel-2.16.x 060313a7c -> abe610d65
  refs/heads/master e3940341c -> b5631c2e6


CAMEL-9608 camel-jpa consumer fails to poll after transaction timeout


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

Branch: refs/heads/master
Commit: b5631c2e67da6dd32706ad6eea669e9bf1536b98
Parents: e394034
Author: Tomohisa Igarashi <tm.igarashi@gmail.com>
Authored: Wed Feb 17 16:11:11 2016 +0900
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Feb 17 09:11:48 2016 +0100

----------------------------------------------------------------------
 .../org/apache/camel/component/jpa/JpaConsumer.java     | 12 ++++++++++++
 1 file changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b5631c2e/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
index 6a3c50c..42b5ff0 100644
--- a/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
+++ b/components/camel-jpa/src/main/java/org/apache/camel/component/jpa/JpaConsumer.java
@@ -90,6 +90,12 @@ public class JpaConsumer extends ScheduledBatchPollingConsumer {
         // must reset for each poll
         shutdownRunningTask = null;
         pendingExchanges = 0;
+        
+        // Recreate EntityManager in case it is disposed due to transaction rollback
+        if (entityManager == null) {
+            entityManager = entityManagerFactory.createEntityManager();
+            LOG.trace("Recreated EntityManager {} on {}", entityManager, this);
+        }
 
         Object messagePolled = transactionTemplate.execute(new TransactionCallback<Object>()
{
             public Object doInTransaction(TransactionStatus status) {
@@ -130,6 +136,12 @@ public class JpaConsumer extends ScheduledBatchPollingConsumer {
                     if (!isTransacted()) {
                         LOG.warn("Error processing last message due: {}. Will commit all
previous successful processed message, and ignore this last failure.", cause.getMessage(),
cause);
                     } else {
+                        // Potentially EntityManager could be in an inconsistent state after
transaction rollback,
+                        // so disposing it to have it recreated in next poll. cf. Java Persistence
API 3.3.2 Transaction Rollback
+                        LOG.info("Disposing EntityManager {} on {} due to coming transaction
rollback", entityManager, this);
+                        entityManager.close();
+                        entityManager = null;
+                        
                         // rollback all by throwning exception
                         throw cause;
                     }


Mime
View raw message