Hibernate connections to MySQL my db are not closing. After clicking 10 times in like 10 second, I get this connection statistics from MySQL Workbench (in my development mac
private static final ThreadLocal<Session> session = new ThreadLocal<Session>();
public static void closeSession() throws HibernateException {
Session s = session.get();
if (s != null) {
s.close();
session.remove();
}
}
actually I am doing like this and it works
Well it seems I was creating SessionFactory everytime. There's a nice class here at the link, making SessionFactory static solved the problem. http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html#tutorial-firstapp-helpers