File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes httpsesssion  versus hibernate getNewSession() relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "httpsesssion  versus hibernate getNewSession() relationship" Watch "httpsesssion  versus hibernate getNewSession() relationship" New topic

httpsesssion versus hibernate getNewSession() relationship

Elanges waran

Joined: Dec 13, 2007
Posts: 17
Hi All,

I developed a web application used hibernate with Jsp and servlet . also I used a hibernateUtil for ORM to Database. In my application i used on servlet
HttpSession session = request.getSession(); and in Session session = HibernateUtil.getNewSession() for execute our sql query. I want a clarification between httpseession and hibernate session. Kindly Reply in soon..


Regards,<br />K.Elanges
Walter Bernstein
Ranch Hand

Joined: Dec 19, 2007
Posts: 57
HttpSession is a context object for a user in a web application. You can identify a user session by the sessionId (stored in a cookie or request parameter). You can store state in the session. Typically a session consists of many user requests. A session is destroyed on timeout, or manually (e.g. on logout). Typical scenario: user logs in, does some stuff, logs out.

"Hibernate session" is a bad name. A better name would have been UnitOfWork. The hibernate session is a context object for the hibernate framework. The session provides access to the db (query, criteria, ...). All objects you load via the hibernate session are registered in the hibernate session. Hibernate will take care to persist any changes made to the session's objects. Typically a hibernate session is a short living object (does'nt live longer than a user request).
I agree. Here's the link:
subject: httpsesssion versus hibernate getNewSession() relationship
It's not a secret anymore!