org.hibernate.HibernateException: No Session found for current thread异常处理

在整合spring3+hibernate4+Struts2时遇到org.hibernate.HibernateException: No Session found for current thread的问题。解决方法包括在Hibernate配置文件中添加过滤器,确保过滤器配置在Struts2之前,或者使用OpenInViewFilter,但注意其可能带来的性能影响。通过调整查询方式,避免在不需要时保持Session打开,可以有效避免此类异常。
摘要由CSDN通过智能技术生成

我今天在整合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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值