Nested Transaction

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Nested Transaction

sgolestane
Does BTM support nested transactions? I'm getting a "NestedTransactionNotSupportedException" from Spring and wasn't sure if the problem is from my configuration or TM.
Reply | Threaded
Open this post in threaded view
|

Re: Nested Transaction

Ludovic Orban
Administrator
Hi,

BTM does not support nested transactions, mostly because AFAIK there is no single database that supports them as well.

May I ask why you want them ?

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: Nested Transaction

sgolestane
In reply to this post by sgolestane
Here is a use case:

1- get a message from *request* JMS queue.
2- validate the message if validation past move to step 3 if not move the message to *bad-request* queue and go to step 4.
3-save the message in database. if not successful move the message to *bad-request* queue and go to next step.
4-create responce and send it to *response* queue.

*A new transaction will start at step 1 which will commit/rollback at step 4.
*each JMS or database operation will be done in nested transaction.

Alex_q wrote
Does BTM support nested transactions? I'm getting a "NestedTransactionNotSupportedException" from Spring and wasn't sure if the problem is from my configuration or TM.
Reply | Threaded
Open this post in threaded view
|

Re: Nested Transaction

Ludovic Orban
Administrator
All that can be done within a single XA transaction. Simply start your transaction, go to step #1 then commit after step #4.

At step #2, if validation fails you just send your message to bad-requests queue.
At step #3, if you get a SQLException send your message to bad-requests queue.

The TM will take care of committing messages sent to response-queue, bad-requests (if a message was sent) and the database (if something was written).

I don't see any value nested transactions would add here.

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: Nested Transaction

sgolestane
Hey Ludovic, Thanks for the suggestion.


Here is quote from Sun's JavaTM Message Service Tutorial http://java.sun.com/products/jms/tutorial/1_3_1-fcs/doc/jmsj2ee.html

"Your application cannot, however, both send a JMS message and receive a reply to it within the same transaction; the restriction described in Section 5.2.2, "Using JMS API Local Transactions," still applies."

Ludovic Orban wrote
All that can be done within a single XA transaction. Simply start your transaction, go to step #1 then commit after step #4.

At step #2, if validation fails you just send your message to bad-requests queue.
At step #3, if you get a SQLException send your message to bad-requests queue.

The TM will take care of committing messages sent to response-queue, bad-requests (if a message was sent) and the database (if something was written).

I don't see any value nested transactions would add here.

Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: Nested Transaction

Ludovic Orban
Administrator
The Sun documentation is right although a bit unclear.

This is how it should have been written to make it more understandable:

Your application cannot, however, both send a JMS message and receive a reply to it (it == the message you just sent) within the same transaction.

The use case you described is not impacted by this statement so you can implement it - for instance - the way I described it. It is a very common pattern to received a message, update a DB then send a message in a single transaction and often the reason #1 to use JTA. Feel safe about it.

Ludovic