tags:

views:

147

answers:

1

please tell me is there anytool to monitor hibernate sessions in case of session leakage

Thank you.

+1  A: 

You can enable Hibernate statistics to see the number of open and closed sessions: hibernateConfiguration.setProperty(Environment.GENERATE_STATISTICS, "true") Then use SessionFactory.getStatistics() to look at open and closed sessions. That should tell you if you are leaking sessions.

Finding out where the leak is coming from is another issue. I've done that by centralizing all the code to get a session and then storing a stack trace with every session open (by thread) and removing it when the session closes. Periodically, look at the list of open sessions and whichever ones are left are the leaked ones. Profiling tools can make this easier if you can reproduce the leak in a controlled environment.

Brian Deterling