Which one of the following statements regarding the client view of exceptions received from an enterprise bean invocation is correct?
1.The client can safely continue the transaction by retrying the operation if an application exception is received.
2.The 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.
3.The client can safely continue the transaction by retrying the operation if a non-application exception is received.
4.A local client cannot continue a transaction if javax.transaction.TransactionRolledbackLocalException is received. 5.A remote client cannot continue a transaction if javax.transaction.TransactionRolledbackException is received.
From the option given for the above question,I think second option is the correct answer.But in the site option (5) is given as the right answer.According to me if option (5) is correct then option (4) should also be the correct answer.Pls clarify.
I'll drop a hint why (4) is incorrect: Are you sure that a client can ever receive javax.transaction.TransactionRolledbackLocalException?
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Joined: Mar 24, 2005
According to the Specs, if the bean uses Container Managed Transaction Demarcation with transaction Attribute Mandatory,Supports and Required and if an exception is thrown then the client will receive TransactionRolledbackException if the client is remote and TransactionRolledbackLocalException if the client is local.
If the bean uses any other attribute then javax.ejb.EJBException is thrown.
Is the exception thrown is dependent on the transaction Attribute?
Also what I noted is with Bean Managed Transaction Demarcation, the exception thrown is javax.ejb.EJBException for local client.Pls clarify
Thanks and Regards Shiv
Joined: Sep 29, 2002
Please reread the question carefully. The information is there to tell you if the question is correct or incorrect. This is the kind of question that can easily cost you points in the real exam if you are just a little careless of if you do not know the exception hierarchy.
Let me give you another hint: what is the difference between an exception thrown to a local client and an exception thrown to a remote client?
The local client receives javax.ejb.TransactionRolledbackLocalException which is the subclass of javax.ejb.EJBException. The option 4 in the above question is incorrect because there is no class javax.transaction.TransactionRolledbackLocalException. The remote client receives javax.transaction.TransactionRolledbackException.
The javax.transaction.TransactionRolledbackException is a subclass of java.rmi.RemoteException and is thrown for remote clients. Thus pont 5 is correct.
For local clients javax.ejb.TransactionRolledbackLocalException is thrown which is a subclass of javax.ejb.EJBException and in point 4 the package is worng.
As far as point 2nd is concerned in the bean class you can catch the application exception and can continue the transaction(may be calling other methods ) after checking that the transaction has not been marked for rollback but the client can't do the same.
Hope that helps.
Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
Joined: Mar 24, 2005
Thanks for the feedback.Perhaps I need to read the question a little careful.