Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session help

 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read the book Pro Hibernate 3, and may have gained some confusion in the process My questions is do I always have to close a session when I am done with it? I would think I would but the authors of the book do not do this in their code examples. For example, the authors use the following hibnernate helper class below but do not ever close the session when using this helper class:

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My questions is do I always have to close a session when I am done with it?

By and large the answer to that is yes. Unless you are explicitly flushing the session it will become stale (i.e. the objects in it are not really representative of the data in your database) if you keep it open for a long time.
 
Andy Hahn
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Below is a closeSession() method in case anyone wants to use the code in this post:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic