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

*爱你&永不变心* 提交于 2019-11-30 21:11:06

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!