Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help on setRollBackOnly

 
Ram Venkat
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,


Can any one give good example or explantion of setRollBackOnly / getRollBackOnly method in UserTransaction and EJBContext.


Thanks In Advance
 
Raghu Kashyap
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would use this in a BMP entitybean. One example is when you try to purchase something on amazon and you update the DB with the purchase of the item and then the Creditcard transaction fails for some reason you setRollBackonly to fail the transaction. So further processing will stop if you do a getRollBackOnly.

Maybe this makes sense :-)

Amazon might not use BMP but I just chose that as an example.
 
Benoît de Chateauvieux
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raghu Kashyap,

I understand your example but... Why do you invoke setRollBackOnly when you can do a transaction.rollback() ?
Thanks,

Beno�t
 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actaully it is illegal to use setRollbackOnly and getRollbackOnly methods of the EJBContext interface on BMT beans. You should only use the transaction.rollback() and the getStatus methods available with the UserTransaction interface.... the setRollback and getRollback methods are only used with CMT beans where if you are throwing an application exception and you haven't declared that exception as rollback=true you use the ejbcontext.setRollbackonly before throwing the exception....

Hope this helps
 
fidi fiege
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I guess this is not 100% right. You can use setRollbackOnly() and getRollbackOnly() in CMT thats OK. But even in BMT you can use setRollbackOnly(). The difference is that you use for CMT methods coming directly from EJBContext (setRollbackOnly() and getRollbackOnly()). For the BMT you have to call EntityContext.getUserTransaction() to get a UserTransaction object and there you can use setRollbackOnly() as well, but there is no getRollbackOnly() method available here, instead getStatus() can be used to check if someone called already setRollbackOnly() before. So more or less this is the same for both BMT and CMT just available in different objects and with a different name for the getter method. The difference between setRollbackOnly() and rollback() is more the fact that rollback() directly rolls back the transaction where setRollbackOnly() just markes the transaction for rollback but continues up to the end of the transaction. Only then the transaction is also rolled back. Hope that helps?!
 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EntityContext.getUserTransaction() ? I do not see such a method in the API. Can you please tell me where such a method is available?
 
fidi fiege
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry should be EJBContext and not EntityContext!
 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i went through Mikali's notes and in it, it is clearly specified that you MUST NOT use getRollbackOnly and setRollbackOnly of the EJBContext interface on BMT beans... Its in page number 201... Can anybody clarify this for us please?

Thanks in advance
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic