• 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

CMT

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a stateless session bean with Container Managed Transaction.
In my ejb method, I call DAO class and the DAO class performs databas e operation.SQLException and Exception were caught in DAO class methods and thrown as application exception,DAOException.
My question is "Will the EJB container still able to rollback the transaction when an exception occured as the DAO method catches Exception also? That is, is it ok to catch Exception in class methods called from EJB method?
Thanks in advance,
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Johnson,

Let start with this one:


That is, is it ok to catch Exception in class methods called from EJB method?


It certainly is.


Will the EJB container still able to rollback the transaction when an exception occured as the DAO method catches Exception also?


It depends. If your exception is a system exception (extends the RuntimeException) then you�re safed, the container will rollback the transaction for you. Otherwise, if your exception is a checked exception then you have to rollback the transaction yourself (the container will give the client one more chance to recover and probably retry the transaction). You can do this catching the exception as usual. In the catch block however you must call the setRollbackOnly method on the session context object and rethrow an application specific exception.
Regards.
 
reply
    Bookmark Topic Watch Topic
  • New Topic