提交事务是否关闭会话? [英] Does committing transaction close session?

查看:60
本文介绍了提交事务是否关闭会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的冬眠者.

session.getTransaction().commit()是否关闭会话?因为在api文档中没有提到关闭会话.

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

我的代码中有

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

但是我收到以下异常

org.hibernate.SessionException:会话已关闭

org.hibernate.SessionException: Session was already closed

如果我删除 session.close(),那么我不会得到此异常.

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

推荐答案

您可以找到有关它的更多信息

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).

要检查何时真正关闭,可以尝试在 AbstractSessionImpl.setClosed 方法中设置断点.

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

这篇关于提交事务是否关闭会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆