• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

session help

 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. Below is a closeSession() method in case anyone wants to use the code in this post:

reply
    Bookmark Topic Watch Topic
  • New Topic