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打开
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
有关OpenSessionInViewFilter的参考:
http://docs.spring.io/spring/docs/3.0.x/javadoc-api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html
本文介绍了一个常见的Spring结合Hibernate应用中遇到的问题——请求数据库时出现No Hibernate Session绑定到线程的错误,并提供了具体的解决方案,即通过在web.xml中配置OpenSessionInViewFilter过滤器来解决该问题。
2985

被折叠的 条评论
为什么被折叠?



