org.springframework.dao.InvalidDataAccessApiUsageException
2010-11-23 17:16
483 查看
3.在action中调用一个类,并要把这个类注入到spring中去,在这个class里操作dao时报:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.这个错。原因:在项目中使用S2SH时,会启用会开启OpenSessionInViewFilter来阻止延迟加载的错误,但是在我们开启OpenSessionInViewFilter这个过滤器的时候FlushMode就已经被默认设置了MANUAL,如果FlushMode是MANUAL或NEVEL,在操作过程中Hibernate会将事务设置为readonly.所以在增加,删除,修改操作时就会报以上的错误。
解决办法:直接修改OpenSessionInViewFilter过滤器的配置,配置过滤器的时候配置时候直接指定flushMode。采用下面的方式即可:代码如下: 在web.xml文件中添加如下代码:即可解决延迟加载与上面的错误信息
<!--
hibernate由于设置了延迟加载,在action中并没有真正地查询数据.
当跳到jsp页面上要显示数据时,hibernate中的session却已经关闭,导致数据无法显示 该过滤器的作用就是可以避免这种情况
-->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenS essionInViewFilter
</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
解决办法:直接修改OpenSessionInViewFilter过滤器的配置,配置过滤器的时候配置时候直接指定flushMode。采用下面的方式即可:代码如下: 在web.xml文件中添加如下代码:即可解决延迟加载与上面的错误信息
<!--
hibernate由于设置了延迟加载,在action中并没有真正地查询数据.
当跳到jsp页面上要显示数据时,hibernate中的session却已经关闭,导致数据无法显示 该过滤器的作用就是可以避免这种情况
-->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenS essionInViewFilter
</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
相关文章推荐
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read
- OpenSessionInViewFilter与org.springframework.dao.InvalidDataAccessApiUsageException
- org.springframework.dao.InvalidDataAccessApiUsageException: The given object has a null identifier:
- org.springframework.dao.InvalidDataAccessApiUsageException 原因和解决
- org.springframework.dao.InvalidDataAccessApiUsageException
- org.springframework.dao.InvalidDataAccessApiUsageException
- OpenSessionInViewFilter与org.springframework.dao.InvalidDataAccessApiUsageException
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in r...
- org.springframework.dao.InvalidDataAccessApiUsageException
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' mar
- org.springframework.dao.InvalidDataAccessApiUsageException
- org.springframework.dao.InvalidDataAccessApiUsageException问题解决
- OpenSessionInViewFilter与org.springframework.dao.InvalidDataAccessApiUsageException
- org.springframework.dao.InvalidDataAccessApiUsageException
- org.springframework.dao.InvalidDataAccessApiUsageException: ERR value is not an integer or out of ra
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read
- 异常积累:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in
- org.springframework.dao.InvalidDataAccessApiUsageException:The given object has a null identifi的解决方案
- hibernate异常:org.springframework.dao.InvalidDataAccessApiUsageException解决办法
- org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER)