aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Transaction in EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Transaction in EJB" Watch "Transaction in EJB" New topic
Author

Transaction in EJB

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1373
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?
Shahri Shahri
Greenhorn

Joined: Mar 08, 2005
Posts: 2
Kri Shan,

Just check the article in the following url: http://www.kevinboone.com/ejb-transactions.html
ejb-transactions
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704

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.


    I think, therefore I exist -- Rene Descartes
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Transaction in EJB