org.hibernate.SessionException: Session was already closed

http://blog.****.net/palmer_xu/article/details/7332694

 

今天写hibernate时候遇到一些异常

代码:

org.hibernate.SessionException: Session was already closed

 

出现异常情况:

org.hibernate.SessionException: Session was already closed

 

出现以上原因是Session关闭

 

如果不是使用的SessionFactory.getSession()来获得Session。

        而是使用SessionFactory.getCurrentSession()方法来获得Session时,当事务结束的时候,不管是提交还是回滚事务,hibernate会自动关闭Session的,

所以不需要手动关闭。

 

但是如果对于查询了?就没有启动事务管理!session啥时候关闭?待解决!因为如果在control层初始化被懒加载的对象汇报no session 异常的。