Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

UserTransaction and setRollbackOnly

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I know that, in case of CMT, a transaction marked as rollBackOnly will rollback instead of commit.

I the case of BMT, I can't find the expected behaviour in the specs.
For me, a code like this

will throws an exception because you can't do a commit in a Transaction marked for rollback.
I read in the Javadoc of javax/transaction/UserTransaction.html#commit():
RollbackException - Thrown to indicate that the transaction has been rolled back rather than committed.

I tested it in my JBoss and I get:
Exception in thread "main" javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state

Thanks in advance for your opinion,

Beno�t
[ February 26, 2008: Message edited by: Beno�t de CHATEAUVIEUX ]
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand what behavior you expect here?

You have set it to roll back. So whatever may be the condition, it has to rollback. Now if you attempt to commit after that, what you think should happen?
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The setRollbakOnly() is applicable to the CMT only. You can not use it with User transaction. To rollback the user transaction yo have to explicitly use the rollback() instead of commit().

Thanks
 
Benoît de Chateauvieux
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gladwin and Narendra,

Thanks for your answers.
Gladwin > Now I know that a commit on a transaction marked as RollbackOnly will throw a javax.transaction.RollbackException

Narendra > UserTransaction has a setRollbackOnly() method too.
See http://java.sun.com/j2ee/1.4/docs/api/javax/transaction/UserTransaction.html

Thanks,

Beno�t
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Though the UserTransaction has the setRollbackOnly method, In BMT your transaction is demarcated by your ut.begin and ut.commit or ut.rollback commands. EJB spec enforce that you can not call setRollbackOnly for BMT transaction, otherwise it will throw the Exception which you are receiving.

When you are using the BMT tracsaction, you are controlling the transaction, there is no need to notify the container that the transaction is for the rollback only as the container is not controlling your transaction demarcation.

Thanks
 
Benoît de Chateauvieux
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Narendra,

I have tested it with this code:

And it doesn't throw any exception.

You can call setRollbackOnly for BMT transaction but, of course, you can't do a commit on a Transaction marked for rollback.

The chapter 13.3.3.1 of the spec is about EJBContext.getRollbackOnly():

An enterprise bean with bean-managed transaction demarcation must not use the getRollbackOnly and setRollbackOnly methods of the EJBContext interface.

An enterprise bean with bean-managed transaction demarcation has no need to use these methods, because of the following reasons:

� An enterprise bean with bean-managed transaction demarcation can obtain the status of a transaction by using the getStatus method of the javax.transaction.UserTransaction interface.

� An enterprise bean with bean-managed transaction demarcation can rollback a transaction using the rollback method of the javax.transaction.UserTransaction interface.



Thanks for your help,

Beno�t
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Sorry for my previous post. I had not checked if the container throws exception or not when we used setRollbackOnly only for user managed transactions. While reading the Spec I understand only that this method is not very useful when the transaction is not CMT. If you determine that the transaction have no fruitful results, you can rollbak the transaction at same point only, as you have full control on the transaction, there is no need to set the transaction for rollbak only and then rollback the transaction.

Thanks
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that in the case of BMT, only BMT can invoke UserTransaction methods in the user code. EJBContext methods setRollbackOnly() and getRollbackOnly() only apply to CMT. UserTransaction methods include commit(), rollback(), getStatus(), and setRollbackOnly().

Originally posted by Narendra Dhande:
Hi,

The setRollbakOnly() is applicable to the CMT only. You can not use it with User transaction. To rollback the user transaction yo have to explicitly use the rollback() instead of commit().

Thanks


[ March 11, 2008: Message edited by: Frank Stein ]
 
brevity is the soul of wit - shakepeare. Tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic