This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

Another Exception question

 
jeff mutonho
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which one of the following statements regarding the client view of exceptions received from an enterprise bean invocation is correct?
1The client can safely continue the transaction by retrying the operation if an application exception is received.
2The client can safely continue the transaction by retrying the operation if an application exception is received, but only after checking the transaction has not been marked for rollback.
3The client can safely continue the transaction by retrying the operation if a non-application exception is received.
4A local client cannot continue a transaction if javax.transaction.TransactionRolledbackLocalException is received.
5A remote client cannot continue a transaction if javax.transaction.TransactionRolledbackException is received.



Solution :

Answer 5 is correct. javax.transaction.TransactionRolledbackException indicates to a remote client that the transaction has definitely been marked for rollback. Therefore it is pointless for the client to continue with the transaction, as the transaction cannot be committed.

Answers 1 and 2 are incorrect. It is potentially dangerous retrying to continue with a transaction after receiving an application exception because it is not always possible to determine the state of the enterprise bean. For example, if the container started a transaction just before invoking an enterprise bean with container-managed transaction and the enterprise bean throws an application exception and does not mark the transaction for rollback, the container commits the transaction before re-throwing the application exception to the client. In this scenario, it is not possible for the client to continue with the transaction on receiving the application exception.

Answer 3 is incorrect. The container will discard the bean instance if a non-application exception is thrown. Answer 4 is incorrect. javax.transaction.TransactionRolledbackException indicates to a local client that the transaction has definitely been marked for rollback. This exception is a subclass of javax.ejb.EJBException.




If solution 5 is correct , then I don't understand why solution 4 is not.What am I missing?
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: does javax.transaction.TransactionRolledbackLocalException exist?
 
Tejas Gokhale
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.transaction.TransactionRolledbackLocalException exists.
Refer Head First EJB Page#552.
 
jeff mutonho
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He's right ...its suppose to be
javax.ejb.TransactionRolledbackLocalException

not

javax.transaction.TransactionRolledbackLocalException.Indeed
javax.transaction.TransactionRolledbackLocalException does NOT exist

jeff mutonho
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic