No Hibernate Session bound to thread, and configuration does not allow create解决方案

来源:互联网 发布:培训管理数据流程图 编辑:程序博客网 时间:2024/05/29 10:54
参考地址:http://forum.spring.io/forum/spring-projects/data/96622-no-hibernate-session-bound-to-thread-and-configuration-does-not-allow-creation-of-no

1、使用注解实现程序

 dao                           @Repository

service                      @Service        @Transactional

controller                 @Controller     @RequestMapping(value="/")

2、配置Spring 3 + Hibernate 3 (MVC)

启动正常,请求数据库错误,后台报No Hibernate Session bound to thread, and configuration does not allow create错误。

但是事务是配置了的,但是貌似是事务的问题,多方寻求无果,最后在spring网站上找到了解决方案。

3、解决方案在web.xml中加入Hibernate的过滤请求将session打开

[html] view plain copy
 print?
  1. <filter>  
  2.     <filter-name>openSessionInViewFilter</filter-name>  
  3.     <filter-class>  
  4.         org.springframework.orm.hibernate3.support.OpenSessionInViewFilter  
  5.     </filter-class>  
  6. </filter>  
  7.   
  8. <filter-mapping>  
  9.     <filter-name>openSessionInViewFilter</filter-name>  
  10.     <url-pattern>/*</url-pattern>  
  11. </filter-mapping>  
有关OpenSessionInViewFilter的参考:http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html

阅读全文
0 0
原创粉丝点击