本贴转自郝感的技术中心(http://zenganiu1980.spaces.live.com/?_c11_blogpart_blogpart=blogview&_c=blogpart&partqs=cat%3dspring%2bhibernate%2bstuts%2bacegi%25e6%25a1%2586%25e6%259e%25b6%25e7%259a%2584%25e4%25bd%25bf%25e7%2594%25a8%25e7%25bb%258f%25e9%25aa%258c)
以前使用
spring
的
hibernateTemplate
时,发现都无法用
lazyloading
特性因为一旦使用,会报
session close
错误,几经查找资料,终于找到解决方法,就是在
web.xml
中加入下列
filter
:
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>