This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have a stateful session bean that I want to store the userid and password in. In a servlet I assign the values to an instance variable, so that I can access them later. I am doing this so that the user logs into the database as themselves (audit purposes) when doing a transaction. So, I want the connection object to use the information from the stateful session bean to obtain the userid and password. At that time, I need to get a reference to the already existing stateful session bean. When I do a look up with a create(), the values are null in the instance variables. How do I access the session bean after it has been created without the benefit of storing the handle?
In order to use an existing stateful session bean you must have a reference. Now, for a web application, you need to store the reference somewhere in between HTTP requests and that somewhere is usually HttpSession. This, in turn, requires you to use a handle (you can try storing non-serializable objects into HttpSession but you're playing russian roulette if you do that... In a clustered environment, this is not even remotely possible because the container definitely replicates session state somewhere and thus serializes the HttpSession).
Look at this article. Then consider an approach whereby you have an object that returns the reference, which is stored in a transient variable. If the reference isn't there (e.g. after failover) then recreate the reference from the Handle. Kyle