Write operations are not allowed in read-only mode (FlushMode.MANUAL):
来源:互联网 发布:java单例读取文件 编辑:程序博客网 时间:2024/05/20 09:07
转载自:http://blog.csdn.net/cpf929/article/details/18800147
错误信息如下:
ERROR 2014-01-26 19:38:38,504 [org.apache.struts2.dispatcher.Dispatcher] - <Exception occurred during processing request: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.>
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' marker from transaction definition.
at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1175)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:685)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:683)
问题:只读模式下(FlushMode.NEVER/MANUAL)写操作不被允许:把你的Session改成FlushMode.COMMIT/AUTO或者清除事务定义中的readOnly标记。
原因:在Spring的声明事务管理中,有如下配置:
- <tx:attributes>
- <!-- 指定哪些方法需要加入事务 -->
- <tx:method name="save*" propagation="REQUIRED" />
- <tx:method name="delete*" propagation="REQUIRED" />
- <tx:method name="update*" propagation="REQUIRED" />
- <!-- read-only="true":其余方法只读格式,加强其安全性 -->
- <tx:method name="*" read-only="true" propagation="NOT_SUPPORTED" />
- </tx:attributes>
而我保存数据的方法名写成了 register();所以会匹配到最后一个,只读模式。
网上关于这个问题的解释:
错误原因:
解决方法:
web.xml配置里添加
<filter>
</filter>
然后还要再事务方法那刷新flush(),否则不会立刻存储进数据库
this.getHibernateTemplate().save(。。);
getHibernateTemplate().flush() ;
还有一种方法就是直接不用这个过滤器.
<filter-mapping>
</filter-mapping>
如果在交给spring 管理的情况下,在beans.xml 里的配置
- 错误:Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into
- Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushM
- 错误:Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)..
- Hibernate Write operations are not allowed in read-only mode (FlushMode.MANUAL)
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)..
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into
- Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn
- 错误:Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)..
- Write operations are not allowed in read-only mode (FlushMode.MANUAL): 解决方法
- Write operations are not allowed in read-only mode (FlushMode.MANUAL):
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)异常解决方法
- Write operations are not allowed in read-only mode (FlushMode.MANUAL)
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)
- 解决Spring4+Hibernate4遇到的 Write operations are not allowed in read-only mode (FlushMode.MANUAL)
- Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushM
- 【数据结构】图邻接表存储实现
- android:layout_weight的真实含义
- 第8周
- HDU 3972 1 M possible (hash)
- 开源CT系统
- Write operations are not allowed in read-only mode (FlushMode.MANUAL):
- 新视野大学英语读写教程(第二版)第四册练习答案
- 排序算法(二)交换排序
- C++primer plus第六版课后编程题答案16.8
- eclipse 运行非常慢,卡顿,最快的解决办法?
- 并查集
- Learn to Give Up
- 大学英语四级最常考的100个短语总结
- strutse(1)