users@glassfish.java.net

Re: JMS, JPA, XA, rollback and all the rest

From: <glassfish_at_javadesktop.org>
Date: Fri, 15 Jan 2010 07:42:03 PST

Assuming you've configured this correctly (and I haven't scrutinised it for errors), you will have two distinct XA transactions.

Transaction 1 contains

* sendMessage() sends a message to the queue
* sendMessage() calls addLoggingMessage() to write to the database

Transaction 2 contains

* The MDB receives a messages from the queue
* The MDB calls addLoggingMessage() to write to the database

Each of these two transactions will commit or rollback the database and JMS provider atomically using a two-phase protocol.

Your question suggests you might have been expecting a single transaction to encompass all four steps.This is not the case. When the MDB receives a message it will do so in a different transaction from that which was used to send the message.

It has to - the JMS provider will not deliver messages until they've been committed by the sender (that's a rule of JMS). So you must must send and consume a given message in separate transactions.

Nigel
[Message sent by forum member 'nigeldeakin' (nigel.deakin_at_sun.com)]

http://forums.java.net/jive/thread.jspa?messageID=381189