Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

httpsesssion versus hibernate getNewSession() relationship

 
Elanges waran
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..

Thanks,
K.Elanges
 
Walter Bernstein
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic