Hello all,
I could not find answers to all the scenarios in page 556, here is a compilation of answers(mine and borrowed from forum). Please post your comments if anything is wrong:
1. A message-drive bean's onMessage() method catches an application exception. Can it rethrow the application exception to the container?
-- No, the onMessage() method does not declare any application exceptions and hence cannot throw the application exception. It can wrap the exception in a runtime exception and rethrow it.
2. A session bean using CMT has a method marked with the NotSupported transaction atrribute While the method is running. the bean calls setRollbackOnly() on its context. will this cause an exception? What kind?
-- Yes, it will cause an exception. It will be an illegalStateException.
3. A message-drive bean, in the onMessage() method, calls getCallerPrincipal(). What happens?
-- Again, an illegalStateException is thrown
4. A session bean using CMT has a method marked with the Madatory transaction attribute. The client calling the method is not in a transaction. What happens?
-- TransactionRequiredException/TransactionRequiredLocalException is thrown.
5. A bean realizes it can't commit a transaction, but it doesn't want the client to get an exception. What can the bean do?
-- Call the setRollBackOnly method and simple suppress the application exception.
6. A bean wants the client to get an application exception, but the bean still wants the transaction to commit. What should the bean do?
-- Simply throw the Application exception as is. It does not have to do anything more.
Regards.