Couple of corrections:
1) I meant to put 'JPA 2' in the subject to indicate this being related to new
aries JPA 2 bundles, specifically the jpa-support bundle in this case.
2) My suggestion to delegate the transaction joining logic to a new method
should have said the TransactionToken class, not the TransactionAttribute
class. It would look something like [1]. Since TransactionAttribute already
takes care to only set activeTransaction if one is present, then the null-check
here seems logical to me. Suggestions welcome.
[1]
public void joinTransaction(EntityManager em) {
if (activeTransaction != null)
em.joinTransaction();
}
-----Original Message-----
From: Pitts, Matthew W.
Sent: Wednesday, September 02, 2015 7:48 PM
To: '[email protected]'
Subject: JTA 2 - Bug in XAJpaTemplate#txExpr using TransactionType.Supports?
Hey all, thanks for the great aries bundles.
I'm trying to put together a JPA+JTA setup to do XA across Eclipselink
partitions for replicated entities to begin sharding an existing application.
I've worked through to an almost working setup and I'm running into a problem
that I think may be a bug.
When trying to run txExpr methods on my OSGi-exposed JpaTemplate services I get
a TransactionRequired [1] exception every time I use TransactionType.Supports.
It seems to me that the logic in XAJpaTemplate#txExpr is calling
EntityManager#joinTransaction() regardless of whether there is a current global
transaction. So for situations where you just want your logic to 'support'
running within an existing global transaction, but not create a new one if one
doesn't exist, em.joinTransaction() is still being called.
I'm a bit new to XA/JTA so perhaps I'm not understanding how this should work.
Would it make sense to delegate the joining to a new method
TransactionAttribute that only calls em.joinTransaction if the current
transaction is not null?
I appreciate the input on this. Thanks!
[1] Caused by: javax.persistence.TransactionRequiredException:
Exception Description: No externally managed transaction is currently active
for this thread
at
org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper.throwCheckTransactionFailedException(JTATransactionWapper.java:94)
~[org.eclipse.persistence.jpa.jar:na]
at
org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper.checkForTransaction(JTATransactionWrapper.java:54)
~[org.eclipse.persistence.jpa.jar:na]
at
org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper.registerIfRequired(JTATransactionWrapper.java:131)
~[org.eclipse.persistence.jpa.jar:na]
at
org.eclipse.persistence.internal.jpa.EntityManagerImpl.joinTransaction(EntityManagerImpl.java:2081)
~[org.eclipse.persistence.jpa.jar:na]
at
org.apache.aries.jpa.support.impl.XAJpaTemplate.txExpr(XAJpaTemplate.java:57)
~[na:na]
... 20 common frames omitted
Matthew Pitts
Developer
Security Solutions Design & Automation
Wells Fargo Bank | Tel 336.608.3332 | Cell 336.202.3913 | Kernersville, NC |
MAC D9693-010
[email protected]