How the statefulsession beans maintain their state for each paricular client
Joined: Aug 15, 2001
How the statefulsession beans maintain their state for each paricular client;
take for example shopping cart bean
will the session id created on each user and stored into the server?
if another user comes another session id created stored in to the server?
if the first client comes again how the server knows i should give this session id to this client
Joined: Nov 27, 2004
A common question I get in classes. The answer is: the stateful session bean has NO IDEA who its client is. The client has to maintain the reference to the stateful session bean, not the other way around.
If the SFSB is a remote bean, you can call the method
to retrieve the beans handle (javax.ejb.Handle), which is a serializable reference to the EJBObject. Then you can store that handle someplace where you can get it again. For example, in a web application you can store the handle in the HttpSession. Later, when you want a connection to the stateful session bean, you take your handle and call
which returns the reference to the EJBObject for the stateful session bean (if the bean still exists.. if it doesn't you'll see a NoSuchObjectException)