问题描述
这是我在web.xml里的配置 <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class> org.springframework.orm.hibernate3.support.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> action:里PageResult<UserInfo> pageresult = userService.queryForPages(qo); List<UserInfo> list = pageresult.getPageresult(); System.out.println("----->>>"+list); 这个UserInfo里面 有一个属性:private List<Resource> resources = new ArrayList<Resource>();他们是1对多的关系, 问题是: 我在通过Userinfo获取resources的时候, 报错: failed to lazily initialize a collection of role: com.domain.UserInfo.resources, no session or session was closed 我上面的配置错了吗??? OpenSessionInViewFilter这个不是可以帮我把session开到action层吗》?怎么不好用????????哪里写错了?
解决方案
在 <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 加上<dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher>