File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Stateful session bean question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Stateful session bean question" Watch "Stateful session bean question" New topic
Author

Stateful session bean question

Nikita Deshmukh
Ranch Hand

Joined: Jun 08, 2005
Posts: 38
Given :

7. try{
8. ssb.dbtAcc(30,120000.00,6.5);
10. //some code
11. }catch(java.rmi.NoSuchObjectException ex1){
12. //exception handling code here
13. }catch(java.ejb.EJBException ex2){
14. //exception handling code here
15. }catch(javax.transaction.TransactionRequiredException ex3){
16. //exception handling code here
17. }catch(java.rmi.RemoteException ex4){
18. //exception handling code here
19. }

Assume ssb is a reference to a stateful session bean's remote component interface. which line will never be reached ?

A. line 12
B. line 14
C. line 16
D. line 18

Ans C.

Shouldn,t the answer be B since this is a remote component exception and hence EJBException will not be thrown ??
please advice.

Thanks
Nikita.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
I think you are correct.

C. could be thrown if its a CMT bean with dbtAcc marked as "Mandatory" and if this code isn't running under a transaction.
[ October 05, 2005: Message edited by: Peer Reynders ]
Ram Prasad
Greenhorn

Joined: Dec 26, 2004
Posts: 2
IMHO, C is correct.

javax.ejb.TransactionRequiredException is a system exception and all system exceptions are reported to client as RemoteException for Remote clients and EJBException for local clients.

However, I agree that javax.ejb.EJBException is also not thrown by the bean since the client seems remote.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Ram Prasad:
javax.ejb.TransactionRequiredException is a system exception and all system exceptions are reported to client as RemoteException for Remote clients and EJBException for local clients.


Look closely. The question states "javax.transaction.TransactionRequiredException" not "javax.ejb.TransactionRequiredException"

javax.transaction.TransactionRequiredException ISA java.rmi.RemoteException
Ram Prasad
Greenhorn

Joined: Dec 26, 2004
Posts: 2
Oops. I meant javax.transaction.TransactionRequiredException.

After some thought (still needs to verify in code), I agree that TransactionRequiredException will be recived by the client.

If interested, this is the reasoning for my earlier post:
According to spec 18.1.1 Application exceptions (page 372), "An application exception class must not be defined as a subclass of the java.lang.RuntimeException or of the java.rmi.RemoteException." Taking this into consideration, TransactionRequiredException is a system exception (also mentioned in SCBCD Study kit). And my understanding was that remote clients will recieve RemoteException for any generated System exception. This led me into believing that TransactionRequiredException might be wrapped into a RemoteException before passing it to client.

But since TransactionRequiredException ISA RemoteException, the container simply throws it with out any wrapping.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Yes.

In this case the relevant section in the spec was under "17.6.2.5 Mandatory":

If the client calls without a transaction context, the Container throws the javax.transaction. TransactionRequiredException exception if the client is a remote client, or the javax.ejb.TransactionRequiredLocalException if the client is a local client.


Also note it's "javax.ejb.TransactionRequiredLocalException", not "javax.ejb.TransactionRequiredException" (missed the "Local")
Nikita Deshmukh
Ranch Hand

Joined: Jun 08, 2005
Posts: 38
So finally B is the correct answer ??

Thanks
Nikita
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stateful session bean question