• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Transaction in EJB

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i handle the failure Transaction in EJB?
If power goes off / server crash in the middle of the Transaction, can i handle this situation thru 2 phase-commit (or) rollback?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kri Shan,

Just check the article in the following url: http://www.kevinboone.com/ejb-transactions.html
ejb-transactions
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


How can i handle the failure Transaction in EJB?


There are two schools of thought here (supposing you implement CMT):
  • Let the container roll back the transaction automatically.
  • Catch the exception inside of your code and manually roll back the transaction manually.


  • Believe or not but 1 is tricky, because the container won�t automatically roll back the transaction in all situations. The transaction gets rolled back only if the exception is a runtime exception. If your methods throw application exception, then you might consider 2.
    The second one is very straightforward: all you need to do is to catch the exception and call the setRollbackOnly() on the EJBContext.


    If power goes off / server crash in the middle of the Transaction, can i handle this situation thru 2 phase-commit (or) rollback?


    Not sure if I understand you exactly. The 2PC protocol is used with distributed transactions. If you rollback your local transaction using any of the methods above and your transaction is running within a distributed context, then the 2PC will assure you that the whole-distributed transaction will get rolled back as well. You don�t need to do anything about it.
    Regards.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic