关于springmvc+hibernate中在web.xml里配置error-page跳转到spring的Controller,查询数据库的时候报错。

sun9763 2013-12-13 08:50:11
项目中有一个需求,当web项目发生404情况的时候,要跳转到单独的404页面,并为用户展示其他商品列表。我在web.xml里面配了
<error-page>
<error-code>404</error-code>
<location>/personal/hotgoods.do</location>
</error-page>
跳到hotgoods的时候查询热门商品推荐到404页面,查询语句如下:getSessionFactory().getCurrentSession().createQuery(sqlorhql).list();
在这里的时候就会报
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
web.xml里面还配置了OpenSessionInView
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>
com.framework.common.filter.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
springmvc配置如下:

<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value> classpath:/com/framework/actualapp/resources/spring/action-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
我在网上查过一些资料,报这个错误的原因是getSessionFactory().getCurrentSession()是取的当前事务所绑定的session,因为没有事务,所以就会报错。但我直接在浏览器地址上输入/personal/hotgoods.do跳到action里面的时候都没有错,查询是正常的,所以我觉得非常奇怪,为什么通过<error-page>跳到里面查询就报错了,找了很多地方都没找到解决办法,希望有高手能帮忙分析一下什么原因,感激不尽!
...全文
136 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
sun9763 2014-01-23
  • 打赏
  • 举报
回复
无果。。。。。。。

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧