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 and other Java EE Technologies and the fly likes Invoking Nonexistent Stateful Session Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Invoking Nonexistent Stateful Session Bean" Watch "Invoking Nonexistent Stateful Session Bean" New topic
Author

Invoking Nonexistent Stateful Session Bean

pchen
Greenhorn

Joined: Apr 15, 2004
Posts: 20
I have set up a stateful session bean. Later I will invoke it from a servlet. Suppose the container did not create the stateful session bean, or the stateful session bean timed out. What happens when the servlet tries to invoke it later? Does the invoking method cause an exception? Or does the inkoing method cause the container to redo the life cucle again? If so, how?
I could not find the answer in any of my textbooks.


Yahoo ID: XEngr4Fed<br />SCJP, SCEA
wei wu
Greenhorn

Joined: Apr 27, 2003
Posts: 23
When the stateful session bean times out, the container will swap it out to hard disk which is known as passivation. And the container will swap it into memory which is known as activation, when you later on invoke the ejb object which is associated with this session bean instance.
I hope this will make you clear
pchen
Greenhorn

Joined: Apr 15, 2004
Posts: 20
Thanks for the reply. I guess that my concern is that how does the EJB container behave when the servlet invokes a method on a non-existent stateful session bean. There is NO HttpSession state reference for the stateful session bean. Will the method call automatically cause the EJB container initiate a life cycle through a new naming service invocation, etc.? Or will there be an exception error because of a method call to nothing?
wei wu
Greenhorn

Joined: Apr 27, 2003
Posts: 23
First of all, you should know these terms,
1> home object-- an instance of home interface implementation class which is generated by container. Every EJB class has only one home object.
2> home stub -- since home object is remote object, it must have stub.
3> ejb object -- an instance of your remote interface implementation class which is generated by container also. ejb object is created by home object.
4> ejb object stub -- the stub of an ejb object.
The situation you concerned doesnot exist. First of all, you call create(...) method on home stub which returns an ejb object stub. The ejb object is associated with an session bean instance. Your method call on ejb object stub will be forwarded to ejb object and then forwarded to the associated session bean instance.
Peter Storch
Ranch Hand

Joined: Jun 12, 2003
Posts: 74
Originally posted by wei wu:
When the stateful session bean times out, the container will swap it out to hard disk which is known as passivation.

That's wrong. The container passivates stateful session beans only if they are not used for a while and it needs more memory resource to fullfill other requests.
If a stateful session bean times out the container removes it and you get an object not exist exception or something similar.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
I guess that my concern is that how does the EJB container behave when the servlet invokes a method on a non-existent stateful session bean. There is NO HttpSession state reference for the stateful session bean. Will the method call automatically cause the EJB container initiate a life cycle through a new naming service invocation, etc.? Or will there be an exception error because of a method call to nothing?

You get NoSuchObjectException thrown if the client tries to invoke a method by using a stub to the EJB Object which is not usable - gone, corrupt, whatever.
You get RemoteException thrown if the client, using a stub to a valid EJB Object, invokes a business method on a bean that's already been removed.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
wei wu
Greenhorn

Joined: Apr 27, 2003
Posts: 23
Thanks to Peter Storch, you are right
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Invoking Nonexistent Stateful Session Bean
 
Similar Threads
EJB restrictions for transactions.
Can a stateless session bean be removed by client?
does ejbRemove() ever called on stateful bean?
What does really occur after a system exception?
Container callback restrictions...