| Author |
Stateful Session bean
|
patrick schwarz
Greenhorn
Joined: Dec 18, 2003
Posts: 3
|
|
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?
|
 |
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
|
|
|
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).
|
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
|
 |
Vishwa Kumba
Ranch Hand
Joined: Aug 27, 2003
Posts: 1064
|
|
Does this mean that I cannot store any of the EJB references(home/remote interface) or their handles in a HttpSession Object in both single and clustered environment?
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
Originally posted by Vish Kumar: Does this mean that I cannot store any of the EJB references(home/remote interface) or their handles in a HttpSession Object in both single and clustered environment?
You can store Handle in HttpSession.
|
Groovy
|
 |
Kyle Brown
author
Ranch Hand
Joined: Aug 10, 2001
Posts: 3879
|
|
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
|
Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
|
 |
 |
|
|
subject: Stateful Session bean
|
|
|