今天在做项目,出现了这个问题:
Struts Problem Report
Struts has detected an unhandled exception:
Messages: |
|
File: | org/hibernate/proxy/AbstractLazyInitializer.java |
Line number: |
通过在web.xml中配置过滤器解决,
<!-- 解决延迟加载异常 -->
<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>
这个我用来,但是没起到任何作用,进过摸索,终于发现了,是
延迟加载的问题。、
这个语句是一开始写的:from WeiBo wb left join fetch wb.registerUser where wb.id=id
在registerUser 中role和userType类属性,返回给前台的是使用json来解析的,在这里,role,和usertype都是代理,所有解析的时候就会出错,
所有我们应该将需要的类属性都给加载进来
hql=from WeiBo wb left join fetch wb.registerUser r left join fetch r.role left join fetch r.userType where wb.id=id,
这样问题就解决了。