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:
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.