• 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
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

questions about setRollbackOnly() for BMT

 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Imagine a method ends with a commit() for a BMT.

What happens when you call UserTransaction.setRollbackOnly() in the middle of the method?
Does this mean the commit() will be ignored and the BMT will still roll back, or you get some exceptions?

Thanks.
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't call setRollbackOnly for BMT becuase in BMT you have full control over the transaction and you can simply rollback where you need.

Secondly, setRollbackOnly is the method of EJBContext and not UserTransaction.
[ June 12, 2007: Message edited by: Ali Gohar ]
 
warren li
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UserTransaction does have such method.
 
warren li
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any other explanation?
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are right setRollbackOnly is the method of UserTransaction, but EJB Specification mandates that you should not use setRollbackOnly for BMT if you will do so you will get an exception.

The reason that you don't have this method for BMT is because you have full control over transaction in BMT and you can simply rollback whenever you need.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think when you call setRollbackOnly the Tx will be marked for Rollback and you perform some operation after calling setRollbackonly and finally when you issue commit, you will not be able to commit. I guess it should throw exception saying Tx is already marked for Rollback

I tried calling commit after calling setRollbackOnly for a BMT stateful session bean. I got the below Exception which is a Sub class of javax.transaction.RollbackException...:


weblogic.transaction.internal.AppSetRollbackOnlyException
at weblogic.transaction.internal.TransactionImpl.setRollbackOnly(Transac
tionImpl.java:504)
at weblogic.transaction.internal.TransactionManagerImpl.setRollbackOnly(
TransactionManagerImpl.java:337)
at com.venkat.BMTBean.txMethod(BMTBean.java:44)
at com.venkat.BMTBean_hhabj4_EOImpl.txMethod(BMTBean_hhabj4_EOImpl.java:
45)
at com.venkat.BMTBean_hhabj4_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.activation.ActivatableServerRef.invoke(Activata
bleServerRef.java:90)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:420)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:415)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
--------------- nested within: ------------------
weblogic.transaction.RollbackException: Unknown reason - with nested exception:
[weblogic.transaction.internal.AppSetRollbackOnlyException]
at weblogic.transaction.internal.TransactionImpl.throwRollbackException(
TransactionImpl.java:1683)
at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(Se
rverTransactionImpl.java:325)
at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTran
sactionImpl.java:246)
at weblogic.transaction.internal.TransactionManagerImpl.commit(Transacti
onManagerImpl.java:303)
at com.venkat.BMTBean.txMethod(BMTBean.java:48)
at com.venkat.BMTBean_hhabj4_EOImpl.txMethod(BMTBean_hhabj4_EOImpl.java:
45)
at com.venkat.BMTBean_hhabj4_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.activation.ActivatableServerRef.invoke(Activata
bleServerRef.java:90)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:420)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:415)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)


HTH

Thanks
Venkat
[ June 14, 2007: Message edited by: Venkatesh Rangamani ]
 
Ranch Hand
Posts: 563
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ali Gohar:
Yes you are right setRollbackOnly is the method of UserTransaction, but EJB Specification mandates that you should not use setRollbackOnly for BMT if you will do so you will get an exception.

The reason that you don't have this method for BMT is because you have full control over transaction in BMT and you can simply rollback whenever you need.



Are you sure about that ?
I quote HFEJB : "But if somewhere earlier in your code you can tell that the transaction is doomed, you should call setRollbackOnly()"
 
warren li
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Venkatesh Rangamani. So it throws exception.
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Are you sure about that ?
I quote HFEJB : "But if somewhere earlier in your code you can tell that the transaction is doomed, you should call setRollbackOnly()"



Yes, here is the excerpt from EJB 3.0 Core Specs:

13.3.3.1 getRollbackOnly and setRollbackOnly Methods
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.User-
Transaction interface.
� An enterprise bean with bean-managed transaction demarcation can rollback a transaction
using the rollback method of the javax.transaction.UserTransaction interface.

 
warren li
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry. HFEJB book is about EJB 2.0.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree that for bean mangaed demarcation we should not call '<context>.setRollbackonly()' or '<context>.getRollbackOnly()'. these things are for container managed demarcation.Also a container managed demarcation cannot get 'UserTransaction'.

All the methods in 'UserTransaction' are for bean managed demarcation only.

As part of 'UserTransaction' there is a method 'setRollbackOnly'. if this method must not be used for bean managed demarcation.then why is it for?

Also what is the purpose of 'UserTransaction.getStatus' method if 'UserTransaction.setRollbackOnly' method is not called.
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic