Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stateful Session bean

 
patrick schwarz
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic