aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Doubt with non application exception handling and transactions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Doubt with non application exception handling and transactions" Watch "Doubt with non application exception handling and transactions" New topic
Author

Doubt with non application exception handling and transactions

Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
In Zaikin's guide, at one place it is mentioned

If the client receives the javax.ejb.EJBException or the java.rmi.RemoteException exception from
a method invocation, the client, in general, DOES NOT KNOW if the enterprise bean's method
has been completed or not.
If the client executes in the context of a transaction, the client's transaction may, OR may not,
have been marked for rollback
by the communication subsystem or target bean's container.


while at another place in the same chapter, it is mentioned

The Bean Provider can rely on the container to perform the following tasks when catching a nonapplication
exception:
The transaction in which the bean method participated will be rolled back.
No other method will be invoked on an instance that threw a non-application exception.


what exactly holds ? is a transaction rolled back and the bean instance destroyed by the container on receiving a runtime exception ?
Davide Crudo
Ranch Hand

Joined: Sep 08, 2009
Posts: 62
This is a tricky one ;)
I had the same question... so i did some research...

I didn't find any help in the Java documentation, because they always report the same thing. The Remote Exception is thrown for system exceptions and if you look at some documentations, it tells you that the method might have been completed or not.

The interesting thing, though, is that "RemoteException" is also used by java.rmi to indicate a "communication problem". I didn't find a definitive explanation, but my guess is the following:

If your method completes correctly, and let's say you want to get back a detached entity which is serialized before being sent back, at that point the method is completed but something can happen between the method completition and the sending of the information via rmi, which will cause a communication problem and probably the throwing of that RemoteException. And the client might not know if the transaction was rolled back or not...

As a rule, if there is a System exception, the transaction is rolled back and the bean is discarded. After that, if you call again the same method on a Stateless bean, it might go thru if it was just a temporary glitch (you will not use the original bean, because it was discarded, but you will get another one from the pool).

If on the other hand it was a Stateful bean, you will need to check if the bean is still there. If you call a method of the bean and get "NoSuchEJBException" means that your original bean was discarded...if you call and it is still there.. it means your method completed successfully...

I hope somebody else with more experience might help on this a little more ;)

By the way, you asked:


what exactly holds ? is a transaction rolled back and the bean instance destroyed by the container on receiving a runtime exception ?


... a non application exception is a system exception ... so, yes... it will be rolled back and the bean instance destroyed...

Dave

SCJP, SCBCD
Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
well put Dave. Atleast I can visualize the scenario you are trying to explain. Makes sense. Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Doubt with non application exception handling and transactions