File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes using setRollbackOnly in BMT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "using setRollbackOnly in BMT" Watch "using setRollbackOnly in BMT" New topic
Author

using setRollbackOnly in BMT

muthu kumaran
Ranch Hand

Joined: Oct 26, 2004
Posts: 56
For a bean using BMT Demarcation , if we
set userTransaction.setRollbackOnly()
and if we use userTransaction.commit() at a later point in the code , will the transaction be committed or rolled back

Could anyone throw some ideas on this?

Thanks
cheenu Dev
Ranch Hand

Joined: Nov 13, 2005
Posts: 276
it will be rolled back.
it wont commit for sure.
thats why its there setRollbackOnly() to rollback the transaction..


cheenujunk@gmail.com
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Do you get a RollbackException by doing so ?


[My Blog]
All roads lead to JavaRanch
cheenu Dev
Ranch Hand

Joined: Nov 13, 2005
Posts: 276
you will get RollbackException only on the following cases:

bean throws system exception
calling rollback() on a BMT bean.

calling setRollbackOnly does not throw exception.
its like telling i dont want to commit this transaction.thats it.
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
calling setRollbackOnly does not throw exception.its like telling i dont want to commit this transaction.thats it.

thats correct. but wouldn't you get an transactionrolledbackexception when you try to commit a transaction that has been marked as "setrollbackonly"?


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

As Lynette pointed out, I wanted to know if you'd get one when calling commit()
cheenu Dev
Ranch Hand

Joined: Nov 13, 2005
Posts: 276
no never.
in 376 page of spec says:
If the instance called setRollback-Only(), then rollback the transaction, and re-throw AppException. Otherwise, attempt to commit the transaction, and then re-throw AppException.

also a main thing from documentation is :for transaction rolled back exception
This exception indicates that the transaction associated with processing of the request has been rolled back, or marked to roll back.

so in BMT you start a new transaction.the clients transaction is suspended forever..so in BMT calling setRollbackOnly() rollbacks the BMT bean transaction not the request(clients)..so the exception will not be thrown when you call commit.

but for cmt in case of "required" and "mandatory" if clients transactions there and you call setR.. then exception will be thrown.
hope this is clear
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
hope this is clear

no
cheenu Dev
Ranch Hand

Joined: Nov 13, 2005
Posts: 276
transaction exceptions are thrown only when the client transaction is marked for rollback or rollbacked.

for BMT...the bean starts a new transaction.so the client transaction is suspended.so it(client) wont get exceptions.
is this clear?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: using setRollbackOnly in BMT