users@glassfish.java.net

Re: Stateful Session Bean [One instance per client ? Really ?]

From: <glassfish_at_javadesktop.org>
Date: Sat, 22 Nov 2008 06:12:58 PST

Indeed, the bean identities are different when doing several lookups.
The ServiceLocator pattern would help here. In short, you'd hash the result of the lookup() so that when you need it next time, you get it from the hash, so you preserve the bean identity.

Don't forget in your case we're dealing with 2 types of sessions: the bean session and the web session. The former ensures that once you request a stateful bean, it's identity remains the same across that user session. But when you use the latter, you have a web session on top of the bean session. To ensure that you access the same bean from 2 different JSPs (or when you do a reload), you need to store the bean's identity into the web session scope.
Coming back to the ServiceLocator pattern, you'd store the ServiceLocator instance into the web session scope so that any time you require your session bean from any JSP page (or from a reload) you'd get the same identity.
[Message sent by forum member 'sorincalex' (sorincalex)]

http://forums.java.net/jive/thread.jspa?messageID=318228