Does committing transaction close session?

∥☆過路亽.° 提交于 2021-02-07 07:25:11

问题


I am new to hibernate.

Does session.getTransaction().commit(), close the session? Because in the api documentation it is not mentioned that it closes the session.

In my code I have

session.getTransaction().commit();
session.close();

But I get following exception

org.hibernate.SessionException: Session was already closed

If I remove session.close(), then I do not get this exception.


回答1:


You can find more info about it here. Basically, this depends on how you obtained the session and what is performed in session.getTransaction().commit(); (transaction lifecycle listeners may close session here if some framework you use registered them, for example).

To check when it is really closed, you can try to set a breakpoint in AbstractSessionImpl.setClosed method.



来源:https://stackoverflow.com/questions/30393864/does-committing-transaction-close-session

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