休眠会话已关闭 [英] Hibernate Session is closed

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

问题描述

当我调用方法session.begin事务如下:

  //会话工厂通过bean $ b实例化$ b Session session = this.getSessionFactory()。getCurrentSession(); 
session.beginTransaction();

然后我收到以下异常消息:

  6:13:52,217错误[STDERR] org.hibernate.SessionException:Session关闭! 
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1319)

这个错误的原因可能是什么?

解决方案我认为调用 getCurrentSession()并不能保证会话实际上是打开的。第一次,你应该使用

  Session session = this.getSessionFactory()。openSession(); 
session.beginTransaction();

代替。这个建议实际上与你找到的页面一致。



早些时候:

根据目前可用的信息,我们可以得出结论,错误的原因是会议未开启; - )


When I call the method session.begin transaction as follows:

//session factory is instantiated via a bean
Session session = this.getSessionFactory().getCurrentSession();
session.beginTransaction();

Then I get the following exception message

6:13:52,217 ERROR [STDERR] org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1319)

What could be the cause of this error ?

解决方案

Update: I guess that calling getCurrentSession() does not guarantee that the session is actually open. For the very first time, you should use

Session session = this.getSessionFactory().openSession();
session.beginTransaction();

instead. This suggestion is actually consistent with the page you found.

Earlier:

Based on the information available so far, we can conclude that the cause of the error is the session not being open ;-)

这篇关于休眠会话已关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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