• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

need help on setRollBackOnly

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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 Raghu Kashyap,

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

Beno�t
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry should be EJBContext and not EntityContext!
 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I child proofed my house but they still get in. Distract them with this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic