Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help me on Exceptions and EJB-QL.

 
Vijaya laxmi
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Can U give me some help on these Questions and also tell me where to read to get a good level of confidence in EJB-QL.I read HFEJB.But I want to know more in that bcos many people in java ranch told to be more confident in that.
1.What happens when MDB onMessage method catches an Application Exception?
2.Bean realizes that it cant commit transaction,but it doesn't want the client to get an exception,what can the bean do.
3.Bean wants a client to get an application exception,but the bean still wants the transaction to commit.What should the beand do.

I think 1A..Will the bean through EJBException.
2A..can it say setRollBackOnly()
3A..
Please verify me the answers.

Thanx a lot in advance.
Vijaya
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.What happens when MDB onMessage method catches an Application Exception?

Well, tricky one. Actually, since an MDB has no client view, it must not throw application exceptions. It doesn't make big sense for an MDB to throw and application exception and catch it in the same method. The only thing it could do then, would be to wrap it in an EJBException which would be caught by the container. The container would then log the exception, rollback the transaction and discard the MDB anyway. The bottom line is that it is not worth throwing and catching an application exception in the same method and wrap it in a system exception. Why not throw the system exception right away?

2.Bean realizes that it cant commit transaction,but it doesn't want the client to get an exception,what can the bean do.

Nothing, an exception is thrown in all cases according to the spec. Check out cheat sheet on exception handling for more details.

3.Bean wants a client to get an application exception,but the bean still wants the transaction to commit.What should the beand do.

The bean itsefl cannot do much when application exception occur as they are thrown unchanged to the client. In case, the bean uses CMT, the container will try to commit/rollback the transaction depending on what getRollbackOnly() returns. Otherwise, the burden of committing/rolling back the transaction lies on the client as depicted on my above-mentioned cheat sheet.

Hope this helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic