• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate session

 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
in my util i have 2 method.
1.return session obj
2.close session obj.

in my action(struts) class i am calling method 1 to get session obj which
will go to db , get some data . Then i am closing the session and pass the
data to jsp.

I am creating ThreadLocal obj and setting the session to thread.


if i send the request again will i get the same session or not, as i am
closing the session in every action class.

Let me know clearly on this issue.

Raj.
 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

clarify me.
 
Nathan Hook
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your case. I would bet that you are going to get a new session every request.

It might be a better idea having your Session created in a Filter and placed into the ThreadLocal. Then your action doesn't need to worry about opening a new session, it just uses the one found in the ThreadLocal. The filter would then close the session when the request to the server is completed.

I believe this is called the one session per request pattern. Not positive though. But it is quite popular for web development.
 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you tell me how to maintain old session to track the same user's information.After sending the response the session will be lost ,then how
to track the same user in the next request.

Please let me know,
if i am using struts and using hibernate util class to open and close
session:
Where to open and where to close session and how to track for multiple requests of same user.



Awaiting for your reply,
Raj.
 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic