You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/02/17 09:14:27 UTC

[1/3] camel git commit: CAMEL-9608 camel-jpa consumer fails to poll after transaction timeout

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...@gmail.com>
Authored: Wed Feb 17 16:11:11 2016 +0900
Committer: Claus Ibsen <da...@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;
                     }


[3/3] camel git commit: CAMEL-9608 camel-jpa consumer fails to poll after transaction timeout

Posted by da...@apache.org.
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/b7271891
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b7271891
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b7271891

Branch: refs/heads/camel-2.15.x
Commit: b72718912043d8c7c1e592c64c7942f2c7e9c941
Parents: bdbfc17
Author: Tomohisa Igarashi <tm...@gmail.com>
Authored: Wed Feb 17 16:11:11 2016 +0900
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Feb 17 09:14:16 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/b7271891/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 b378e8d..ee5c7b2 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
@@ -88,6 +88,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) {
@@ -128,6 +134,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;
                     }


[2/3] camel git commit: CAMEL-9608 camel-jpa consumer fails to poll after transaction timeout

Posted by da...@apache.org.
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/abe610d6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/abe610d6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/abe610d6

Branch: refs/heads/camel-2.16.x
Commit: abe610d65d91f0cd2ee74a80c0efffba90ad9cb3
Parents: 060313a
Author: Tomohisa Igarashi <tm...@gmail.com>
Authored: Wed Feb 17 16:11:11 2016 +0900
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Feb 17 09:14:00 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/abe610d6/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;
                     }