Spring3与hibernate4 整合 (No Session found for current thread)
来源:互联网 发布:中国历史故事网软件 编辑:程序博客网 时间:2024/04/28 04:32
最近将hibernate3与spring的整合 ,更换称 hibernate4 出现了一大堆问题。其中一个
原因为:
hibernate4 实现了事务的处理 。spring不在支持HibernateDaoSupport 在hibernate3中我们可以在DAO中继承Spring的HibernateDaoSupport 来实现Session的开启但hibernate4中不在提供其支持,故需要我们自行开启。
在web.xml中需要配置一个Filter
<filter>
<description></description>
<filter-name>openSessionInViewer</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewer</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>openSessionInViewer</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
前提要在Struts 的前面,不然无效
解决二:
在Spring的Applicationcontext.xml中开启注解事务
在相应的方法前使用
@Transactional
public List<TUser> findall() {
Session session = sessionFactory.getCurrentSession();
Query query = session.createQuery(" from TUser u order by u.MId desc");
@SuppressWarnings("unchecked")
List<TUser> tuses = query.list();
return tuses;
}
- Spring3与hibernate4 整合 (No Session found for current thread)
- spring3与hibernate4整合的 (no Session found for current thread)
- Hibernate4 与 spring3 集成Hibernate4 No Session found for current thread
- 关于Spring3.2+Hibernate4.1整合问题:No Session found for current thread
- Hibernate4 与 spring3 集成之后 “No Session found for current thread”
- spring3 与 Hibernate4集成报错 No Session found for current thread
- Hibernate4 No Session found for current thread
- Spring3 + Hibernate4 配置 No Session found for current thread问题的解决
- 关于struts+spring4+hibernate4整合是出现的No Session found for current thread解决
- struts2.3.16+spring4.0.6+hibernate4.3.5整合出现的No Session found for current thread
- Spring framework3.2整合hibernate4.1报错:No Session found for current thread
- spring+hibernate4 报错No Session found for current thread
- Hibernate4 No Session found for current thread原因
- Hibernate4 No Session found for current thread原因
- Hibernate4 No Session found for current thread原因
- Hibernate4 No Session found for current thread原因
- Hibernate4 No Session found for current thread原因
- Hibernate4 No Session found for current thread原因
- HDU 3652 B-number(*数位DP)
- windows_redis
- Spring Boot 学习笔记(九) 数据缓存
- Log4 日志级别
- ExpressionTreeViewer安装与碰到的问题
- Spring3与hibernate4 整合 (No Session found for current thread)
- 题目1480:最大上升子序列和
- Activity的onActivityResult 接收不到返回结果的解决办法
- Android Studio 快捷键设置
- JAVA静默加载Class
- 排序算法之直接插入排序
- NAU8810相关问题
- Node之文件路径处理模块:path模块
- 最小生成树+并查集模板