08-01
18

failed to lazily initialize a collection of role: no session or session was closed

还是做Many-to-One的时候遇见的错误,级联检索不允许。

试验了一下发现了几个解决方法:
1、是把对应一对多的那两个列lazy=true改为lazy=false即可
2、对于查询中如果用的是xxx.load(class,id)则改为xxx,get(class,id)
3在web.xml文件中加入

<filter>
  <filter-name>hibernateFilter</filter-name>
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

  <init-param>
            <param-name>singleSession</param-name>
            <param-value>false</param-value>
        </init-param>

<!--这个--  <init-param>一定要加不然很可能会报错:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
>
</filter>

<filter-mapping>
  <filter-name>hibernateFilter</filter-name>
  <url-pattern>*.mmg</url-pattern>
</filter-mapping>

文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 986
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭