Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to choose between EJBException and Application Exception?  RSS feed

 
Robert Strong
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using BEA Weblogic 8.1, I know that, to rollback the transaction when an error of business logic occurred in Stateless Session Bean, I can either throw EJBException or call context.setRollbackOnly() and then throw ApplicationException.

But I also heard that EJBException might destroy the Bean instance, which would increase Destroyed Bean ratio and Pool miss ratio.

Currently, in Statless Session Bean, I wrapped Application Exceptions like SQLException, FinderException in EJBException. So, in order to reduce Destroyed Bean ratio, should I rollback transaction and throw Application Exception?

any help appreicated!!
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Robert,
The business logic should always throw checked exceptions and this should be the rule not the exception governing any good designing. EJBs should be no exception from this rule as well.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would strongly advise that you forget about ratios and focus on writing code which complies with the EJB spec. You are certainly correct to throw EJBException which wraps SQLException because SQLException is not expected by the client and you want to rollback the transaction. But FinderException is an application exception which is expected by the client, so you should simply allow it to propagate to the container.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!