Hibernate internally uses connection pool and when you call session.close(), the connection is returned to the pool.
All the connections will be closed when you close the sessionfactory.
By default, hibernate will execute the sql statements when you the transaction is committed. so that all the operations in one session will be executed in one shot . You can ask hibernate to execute the sql anywhere within the session by calling flush(). Also, you can change this behavior by setting the flush mode on session like
One more thing I wanted to ask is
If I want to use CMT (Container Managed Transaction), is it mandatory to use EJB.
Cant I use CMT without EJB in hibernate?
Joined: Aug 09, 2005
You can find the best practices in the hibernate reference documentation chapter 24.
Session per request can be implemented using a filter/interceptors. "Open session in View " (OSIV) pattern is a best fit for most of the applications. Please go through this article.
CMT makes sense in the context of EJB. However,I guess, with Spring declarative transaction support, we can avoid EJBs and gain similar benefits. May be someone from the forum can answer it more accurately