aspose file tools*
The moose likes Object Relational Mapping and the fly likes hibernate session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate session " Watch "hibernate session " New topic
Author

hibernate session

raj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 96
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

Joined: Jul 11, 2006
Posts: 96
Hi Ranchers,

clarify me.
Nathan Hook
Ranch Hand

Joined: Jan 10, 2005
Posts: 81
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

Joined: Jul 11, 2006
Posts: 96
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

Joined: Jul 11, 2006
Posts: 96
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate session