PDA

View Full Version : Can JTA and JMS work together ?



potter_ru
Nov 29th, 2004, 06:55 AM
Hello.

I'm trying to understand how JmsTemplate bean can take part in JTA Global transaction. In JmsTemplate.java from org.springframework.org.jms.core package I found two places with session.commit() :

at line 608 (in doSend() code):


if (session.getTransacted() && !TransactionSynchronizationManager.hasResource(get ConnectionFactory())) {
// transacted session created by this template -> commit
session.commit();
}

and at line 727 (in doReceive() code):


if (session.getTransacted()) {
if (conHolder == null) {
// transacted session created by this template -> commit
session.commit();
}
}


For session created in JTA transaction session.getTransacted() returns true, at least for JORAM and ActiveMQ implementation of XASession.

For second condition in first snippet TransactionSynchronizationManager.bindResource() should be called somewhere, but JtaTransactionManager have no such call.

As a result when I'm trying to use JMS XA-aware ConnectionFactory/Connection/Session (slightly modified JONAS JConnectionFactory/JConnection/JSession) with JtaTransactionManager, i'm getting exception
"XASession: commit not allowed" from JSession.

I'm tried to make call to TransactionSynchronizationManager.bindResource(myC onnectionFactory, null) before starting JMS&JTA - it works for doSend(), but does not prevent commit in doReceive().
On the other hand TransactionSynchronizationManager.bindResource(myC onnectionFactory, new ConnectionHolder(null, null)) - can work with doReceive(), but not with doSend(). :(

Can someone show the solution for this issue ?

Regards, Igor