Search code examples
jmsejbjtamessage-driven-bean

JMS and JTA Transactions in Java EE


I think I am not getting something right with JMS and JTA. I am running in a Java EE container with all CMTs. Here is what I am doing:

  1. In an SLSB, write something to the database
  2. From the same method of the SLSB, post a message to a JMS queue
  3. An MDB in the same container listens to the JMS queue and picks up the message
  4. The MDB reads the database

The problem is, the MDB does not see the changes made to the database in step 1.

I verified that steps 1 and 2 happen inside a single XA transaction, as expected. My expectation is that a second XA transaction would start at step 3, after the first XA has been committed. But it seems that the MDB receives the message before the XA transaction that posted the message has been committed.

Is my expectation wrong and what I am seeing is normal?

I am running under JBoss 6. The SLSB is local. Both the SLSB and the MDB are in the same application.


Solution

  • I found the problem! My JMS connection factory was not XA aware. I had looked up /XAConnectionFactory for my JMS connection factory. In spite of the name, that's the wrong resource to lookup for a regular app in JBoss. There is a java:/XAConnectionFactory too, which does not work either. The correct resource name is java:/JmsXA. I used it and everything is working just as expected.

    Thanks to @strmqm for nudging me to the right direction.