S2SH整合SpringMvc报错FlushMode.MANUAL( 只读模式)
来源:互联网 发布:java调用数组sort函数 编辑:程序博客网 时间:2024/06/08 19:11
报错信息
HTTP Status 500 - Request processing failed; nested exception is 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.
只读模式,只能取数据及 不能增删改,
分析错误:
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.写操作在只读模式下不被允许((FlushMode.MANUAL): 把你的Session改成FlushMode.COMMIT/AUTO或者清除事务定义中的readOnly标记。
错误原因:
OpenSessionInViewFilter在getSession的时候,会把获取回来的session的flush mode 设为FlushMode.NEVER。然后把该sessionFactory绑定到TransactionSynchronizationManager,使request的整个过程都使用同一个session,在请求过后再去除该sessionFactory的绑定,最后closeSessionIfNecessary根据该session是否已和transaction绑定来决定是否关闭session。在这个过程中,若HibernateTemplate 发现自当前session有不是readOnly的transaction,就会获取到FlushMode.AUTO Session,使方法拥有写权限。也即是,如果有不是readOnly的transaction就可以由Flush.NEVER转为Flush.AUTO,拥有insert,update,delete操作权限,如果没有transaction,并且没有另外人为地设flush model的话,则doFilter的整个过程都是Flush.NEVER。所以受transaction(声明式的事务)保护的方法有写权限,没受保护的则没有。解决方法一:Spring-servlet.xml
<context:component-scan base-package="com.yzk.carsystem.control"><!-- 只扫描base-package指定包下@Controller注解 --><context:include-filter type="annotation"expression="org.springframework.stereotype.Controller" /></context:component-scan>解决方法二:web.xml
<filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</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>执行方法上添加:getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);
方法三
Dao层HibernateTemplate操作数据时,使用execute方法回调方式实现,如下:原方式:getHibernateTemplate().save(user); 更改后方式:getHibernateTemplate().execute(new HibernateCallback<User>() {@Overridepublic User doInHibernate(Session session) throws HibernateException {session.save(user);return null;}});
0 0
- S2SH整合SpringMvc报错FlushMode.MANUAL( 只读模式)
- 整合SSH时,进行save操作报错Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作
- springMVC学习(S2SH整合)
- 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)写操作不允
- 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)写操作不允
- 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)写操作不允
- Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作不允
- Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作不
- 报错原因 (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker fr
- Spring+Hibernate报错:Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)
- 保存数据报错Write operations are not allowed in read-only mode (FlushMode.MANUAL)
- SpringMVC使用OpenSessionInView提示Session的FlushMode为只读
- Jedis的使用
- linkedlist
- Python学习--21 电子邮件
- linux bash脚本监控启动停止weblogic服务
- 数据库索引的实现原理(面试问题:请说出数据库索引实现原理)
- S2SH整合SpringMvc报错FlushMode.MANUAL( 只读模式)
- java 读取excel 文件 Unable to recognize OLE stream 错误
- podspec文件的写法详解
- MySQL协议.NET Core实现(一)
- 视觉SLAM整理(2)数学篇
- queue 队列
- Star UML 九种图 分析
- [netty]--最通用TCP黏包解决方案:LengthFieldBasedFrameDecoder和LengthFieldPrepender
- EMW3162 AT固件的使用【1】