SSH整合报错:failed to lazily initialize a collection of role

来源:互联网 发布:祝利荣牛熊线指标源码 编辑:程序博客网 时间:2024/05/17 01:03

今天整合ssh,测试Dao层方法时,本地测试了一个方法 没有问题,
然而程序部署到tomcat上时却报了一个错误:
org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException:
failed to lazily initialize a collection of role: com.etoak.bean.Adarea.ads, no session or session was closed

大概意思是延迟初始化集合失败,没有会话或会话关闭。
网上两种办法:
第一种 : 把所有onetomany mangToone 映射的属性加上lazy=”false”,但据说这种办法会让
降低查询效率 。 所以不建议采用 小编就不赘述了
第二种 : 在web.xml中添加如下:

  <filter>         <filter-name>hibernateFilter</filter-name>         <filter-class>         org.springframework.orm.hibernate3.support.OpenSessionInViewFilter         </filter-class>       </filter>        <filter-mapping>         <filter-name>hibernateFilter</filter-name>         <url-pattern>*.action</url-pattern>       </filter-mapping>

不过要注意 同时要在ioc容器中设置sessionFactory的实体bean id为sessionFactory ,不能随意定义了。

0 0
原创粉丝点击