2008-01-17

hibernate:Write operations arenot allowed...)

关键字: hibernate

环境 spring+hibernate3+struts

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

试验了一下发现了几个解决方法:

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>

 

评论
发表评论

您还没有登录,请登录后发表评论

tigerli
搜索本博客
我的相册
8bdf6819-c2f4-4b7a-84cd-d08e62483aaa-thumb
狂飙的蜗牛
共 6 张
最近加入圈子
存档
最新评论