Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
Following are some possible reasons why Hibernate
might not be closing connections:
o You are forgetting to call
Session.close().
This is the most common
cause. Consider carefully how you are handling sessions.
Are you sure you create only one Session per transaction? Are you
certain you close the
Session even if an exception
occurs (ie. in a finally block). Hibernate issues a warning
in the log when an unclosed session is garbage collected,
so
looking there is a good place to start.
Session s = sf.openSession();
try {
// do some work
s.connection().commit();
} catch (Exception e) {
s.connection().rollback();
} finally
{
s.close().close(); //close the session and
user-supplied JDBC connection
}
o Hibernate is doing connection pooling.
Which ConnnectionProvider are
you using? If its not DatasourceConnectionProvider, then
it is probably doing connection pooling. This can cause problems
in certain environments.
Pooling may be disabled for
DriverManagerConnectionProvider by setting
hibernate.connection.pool_size=0 in hibernate.properties.
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.