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:28 UTC
[2/3] camel git commit: CAMEL-9608 camel-jpa consumer fails to poll
after transaction timeout
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;
}