Caused by: org.hibernate.SessionException: Session is closed

来源:互联网 发布:openresty php 编辑:程序博客网 时间:2024/06/04 18:16

Hello,

Does calling commit() or rollback() automatically close the session that you are using? I've checked the doco and it does not mention it, but after issuing a commit (or rollback) I get the following exception:

 

 

 

 

 

To solve this problem, try using this mehod for opening the session

Session session = HibernateUtil.getSessionFactory().openSession();

instead of

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

If we use the getCurrentSession() method , tansaction.commit() / rollback() closes the connection.

If you are ver particular in using getCurrentSession. Then check whether session.isOpen() is true or false based on that

you can handle the issue

原创粉丝点击