Hibernate connections are not closed even with C3P0 + explicit session.close()

后端 未结 2 567
猫巷女王i
猫巷女王i 2021-01-05 21:58

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

相关标签:
2条回答
  • 2021-01-05 22:18
    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

    0 讨论(0)
  • 2021-01-05 22:39

    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

    0 讨论(0)
提交回复
热议问题