org.hibernate.HibernateException: No Session found for current thread异常处理
来源:互联网 发布:程序员电脑壁纸1080p 编辑:程序博客网 时间:2024/06/01 08:30
我今天在整合spring3+hibernate4+Struts2,在测试注册页面的时候,老是报这个异常:org.hibernate.HibernateException: No Session found for current thread,session未打开,经过一番测试,可能有一下原因:
1、在Hibernate.cfg.xml中加上配置:
<property name="current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</property>2、在web.xml中加上OpenInViewFilter过滤器
<!-- OpenInViewFilter --><filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class></filter><filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
3、虽然加上了这个过滤器,但是并没有将这个过滤器放在Struts2过滤器之前,我就是犯了这个错误。
4、OpenInViewFilter这个方法虽然一劳永逸,但是我们知道数据库的连接是很珍贵的,但是会造成性能问题,因此可以采用这种方法:
查询的时候,强制将对应的实体也查询出来,比如查询教师的时候,我这个页面需要用到教学班的信息,就直接调用findTeacherWithClass()方法,将
教学班的信息也查出来,如果不需要教学班的信息则直接调用findTeacher()方法,这样session会及时关闭,同时又不会造成No Session found for current thread异常
复制去Google翻译翻译结果
无会话发现当前线程
0 0
- org.hibernate.HibernateException: No Session found for current thread异常处理
- org.hibernate.HibernateException: No Session found for current thread
- org.hibernate.HibernateException No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread
- 关于异常: org.hibernate.HibernateException: No Session found for current thread
- 关于Hibernate中的update报org.hibernate.HibernateException: No Session found for current thread
- SpringMVC3+Hibernate4问题:org.hibernate.HibernateException: No Session found for current thread
- springMvc 中让人纠结的org.hibernate.HibernateException: No Session found for current thread
- org.hibernate.HibernateException: No Session found for current thread的解决办法
- 在hibernate4中出现org.hibernate.HibernateException: No Session found for current thread
- hibernate异常no session found for current thread
- 用指针玩字符串
- 复数
- 九度OJ 1075 斐波那契数列 (模拟,递归)
- Qt中调用MatlabEngine总结
- C++中相对路径与绝对路径以及斜杠与反斜杠的区别?
- org.hibernate.HibernateException: No Session found for current thread异常处理
- StarUML中时序图添加小人
- Ubuntu Kylin 输入正确的账号密码,登陆后又跳回到登录界面 解决方案
- Android Activity和Intent机制
- mongoDB 介绍(特点、优点、原理)
- 读写配置文件--C语言版
- Codeforces Round #266 (Div. 2) C
- 个人官网第6次升级,艰难地完成了,有史以来最难的一次
- 勿忘初衷