Monday, October 15, 2007

XA Transactions and order of commit

Consider the following scenario;

XA Transaction begin
insert a row into a database table
send a message to JMS Queue with pk of inserted row
XA Transaction commits

An MDB listens on the Queue and process the message. MDB selects the row and updates it.

Here comes the catch. As there is no order for committing it may happen that JMS message may get committed first and hence when MDB processing the message it may occur that database is not yet committed and hence the row is not yet available!
This occurs because there is no ordering mentioned in JTA spec.
In WebLogic (not sure if it is documented supported feature) there is an order for commit. It commits in the same order as the resources getting enlisted.
Bottom line: Make sure to enlist database resource first in similar scenarios.

No comments: