硬盘的BLOG

引导分区

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.javaeye.com/topic/129698

posted on 2008-07-25 23:45 我是一块硬盘 阅读(621) 评论(0)  编辑  收藏 所属分类: JPA


只有注册用户登录后才能发表评论。


网站导航: