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 ]
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.
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.
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().
[ March 11, 2008: Message edited by: Frank Stein ]
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop