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

Stateful session bean question

 
Nikita Deshmukh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So finally B is the correct answer ??

Thanks
Nikita
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic