users@glassfish.java.net

Re: what will happen if we create two userTransaction inside each other?

From: legolas wood <legolas.w_at_gmail.com>
Date: Fri, 20 Apr 2007 14:19:55 +0430

sankara rao bhogi wrote:
> legolas wood wrote:
>> Hi
>> Thank you for reading my post.
>> what is impact and requirement of two userTransaction inside eachother?
>> for example we have a servlet which calls two method from two objects
>> it call them inside one userTransaction.
>> inside each method we have begging and ended some userTransaction.
>>
>> My question is: what is impact of this scenario and what is its
>> requirement from application server side, and resources like database
>> and JMS and ....
> Legolas,
>
> Java EE transactions model if flat and nested transactions are not
> supported. In the scenario you mentioned, if two objects are helper
> class objects,attempting to begin a transaction when it was began
> earlier but not completed, will result in an exception. If two objects
> are EJBs, Java EE programming model ensures that you will not hit the
> nested transactions case.
>
> regards
> sankar
Thank you for your reply.

Do we have Transaction for sending messages to MQ, if yes, how we can
handle it?
Now, image that userTransaction has begin in objectA then:
ObjectA will call a method in ObjectB that will insert a record into
database.
ObjectA will call a method in ObjectC that will send a message into JMS.
userTransaction will commit.

(Now I just imagine that they are objects, but indeed they are web
services themself.)

now:
-We need to start and end database transaction in ObjectB and commit it
ourself, what will be the effect of this on userTransaction that began
in ObjectA?
-Can we find state of userTransaction that we begin in ObjectA within
our methods in ObjectB?
-How to make it possible that rollbaking one of those operation cause
rollbak of the other one?

Thanks