Quote:
I'm not sure if it is a good practice as i've seen in a couple of forums that the hibernateSession becomes stale if we keep it open for too long. But since creating a new HibernateSession each time hits the performance, i don't want to keep creating and closing it every time.
It doesn't hit performance to create a new session for every request. Keeping it in the httpSession is likely to cause trouble and performance issues sooner or later. Eg. first-level cache using up a lot of memory, thread/synchronization issues, automatic-dirty checking taking a long time, etc.
Here is a quote from the documentation at
http://docs.jboss.org/hibernate/stable/ ... ons-basicsQuote:
A Session is an inexpensive, non-threadsafe object that should be used once and then discarded for: a single request, a conversation or a single unit of work.