Hibernate的懒加载问题
时间:2014-05-31 13:46:39
收藏:0
阅读:481
在hibernate中对象中的关联集合,默认是采用懒加载,hibernate是由session来进行数据库访问操作,在访问完action之后,session关闭。使用过滤器可以解决,是的hibernate的session在action使用之后关闭。
在web.xml文件中增加一个过滤器,代码如下:

1 <filter> 2 <filter-name>OpenSessionInViewFilter</filter-name> 3 <filter-class> 4 org.springframework.orm.hibernate3.support.OpenSessionInViewFilter 5 </filter-class> 6 </filter> 7 <filter-mapping> 8 <filter-name>OpenSessionInViewFilter</filter-name> 9 <url-pattern>*.action</url-pattern> 10 </filter-mapping>
评论(0)