aspose file tools
The moose likes Object Relational Mapping and the fly likes session help Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "session help" Watch "session help" New topic
Author

session help

Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
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

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Andy Hahn
Ranch Hand

Joined: Aug 31, 2004
Posts: 225
Thanks. Below is a closeSession() method in case anyone wants to use the code in this post:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session help
 
Similar Threads
tangled up with session management 101
Design benefits of creating Sessionfactory in an utility class
[Hibernate] NoClassDefFoundError
Problem deploying service on Ubuntu Virtual Machine
Error in reading hibernate.cfg.xml after updating hibernate3.jar