JPA(Hibernate)+Spring+Struts2 中延迟加载的解决办法
在entity中的@OneToMany、@OneToOne等中设置fetch = FetchType.LAZY时,在Struts2的Action中进行相关操作出现错误信息如下
org.hibernate.LazyInitializationException: could not initialize proxy no session
解决方法:
在web.xml中加入
<filter> <filter-name>SpringOpenEntityManagerInViewFilter</filter-name> <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>SpringOpenEntityManagerInViewFilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping>
更多其它时刻解决延迟加载错误的方法参见 http://www.iteye.com/topic/129698
1 楼 anone 2008-10-08 谢谢了,好人啊