Loading
JDBC connections leaking in Hibernate

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  Hibernate is leaking JDBC connections ?


Ans)

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.



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

JDBC connections leaking in Hibernate


JDBC connections leaking in Hibernate

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free