• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

USER TRANSACTION , STATELESS SESSION EJB , NEED FEW TIPS

 
ganesh jadhav
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this scenario, please let me know where and why it is going wrong

xYz()
{
try{
utx=getUserTransaction();
utx.begin()
ejbMethod(stateless session ejb with bean managed txn) method () //please see the ejb method down
utx.commit();
}
}ctch()
{
utx.rollback();
}
}

ejbmethod()
{
utx=getUserTransaction();
try{
utx.begin();
method1(); //in this i am updating few table in DB -DB connection is taken in the same method and closed there
method2(); // calling a stored procedure to do smthing etc
method3(); //update smthing else
utx.commit();
}catch()
{
utx.rollback()
}
}



Now problem is if anything goes wrong in method3() in ejbmethod(), the usertransaction utx does not rollback the changes made by
method1 or method2

It does not rollback anything at all .

What is going wrong in here.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure what are you doing with your code??

and one more thing is that JTA doesn't suppourt Nested Transactions.
 
ganesh jadhav
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have removed the utx code from xyz() method , and called the ejbmethod()
still the rollback is not happening.

What is to be done inside the ejb method so that the rollback will happen properly???
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ganesh ,

Post your modified code . so that i can help you.
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganesh,

Please read my post to a very similar thread you created. Also, please slow down and explore BMT via a good reference.

Thanks,
Re
 
ganesh jadhav
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks for the reply ,
I will read about the BMT , you are right i am not enough informed i think. but will please help me for for this Code.

i) We have a daemon which calls this ejb (stateless , bean managed txn).
ii)


[/code]



iv) Conenction is taken from the connection pool.

v) there is piece code in postauth.java, where i get error code, and i throw the postauthException.

vi) In logs it says going for the rollback, but rollback is not performed, i check the db chages , changes are there....no rollback
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganesh,

The BMT code itself is fine on the method. However, there is no data modification going on on this method that I can see, so there is nothing to roll back. Secondly, this code can easily use CMT instead. Thirdly, any "rollback" call here will not effect any other transaction in any other methods since all BMT transactions are isolated from any other existing or nested transactions (as has been stated a few times already). Each time you call "begin" is a separate transaction on it's own...

Hope it helps,
Reza
 
ganesh jadhav
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Please see this piece of code in ejb.

in this method of postauth.java the db changes are done, you mean to say that whatever changes made in that method , won't get rollback using this ejb with userttransaction??

In postauth.java I am not using any usertransaction, I think, I am not using any nested transaction here???

If not , then will it work with the CMT. I know i may sound like newcomer to java but I think it should rollback???

 
ganesh jadhav
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
arr = postAuthObj.authorize(lcObj,Constants.STATE_COMPLT, actNum,conn);

Please see this line in the ejb code.

In the postauth.java , I am making the DB changes, this mehod itself calls other methods and so on. Connection object is same in all db changes.

Is it so that the db changes made in this method, will not be rolled back by the ejb.

Will it be possible to use CMT here for achieving that?

I am not using usetransaction in the postauth.java or anywhere in other calls from this ejb.

 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganesh,

Yes, you can use CMT. Based on what you are saying though, BMT is not the issue. It looks like the data source is not participating the JTA transaction or auto-commit may be set. I would look into that next.

Regards,
Reza
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic