两种方法解决Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker
2018-03-27 22:36
1486 查看
错误描述:
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.存在的问题:
另一种方法:在Dao层中修改
Session session=this.getHibernateTemplate().getSessionFactory().getCurrentSession();
session.setFlushMode(FlushMode.AUTO);
Transaction tran=session.beginTransaction();
session.save(t);
tran.commit();
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.
存在的问题:
只读模式下(FlushMode.NEVER/MANUAL)写操作不被允许:把Session改成FlushMode.COMMIT/AUTO(可以解决)
或者清除事务定义中的readOnly标记(清除readOnly标记有时不管用)
解决方法:
web.xml配置里添加
<!-- OpenSessionInView过滤器 -->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
<!--设置bean的名字,如果为默认的sessionFactory则可以省略-->
<init-param> <!--可以省略-->
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
<!--设置bean的初始化参数,如果为默认的单例默认则可以省略-->
<init-param><!--单例模式,可以省略-->
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<!--解决该问题的关键代码-->
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
另一种方法:在Dao层中修改Session session=this.getHibernateTemplate().getSessionFactory().getCurrentSession();
session.setFlushMode(FlushMode.AUTO);
Transaction tran=session.beginTransaction();
session.save(t);
tran.commit();
相关文章推荐
- 解决 Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker
- 解决 Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from
- 解决 Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from
- Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition
- Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition
- [SSH] Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction
- Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition
- Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction
- Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition
- Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition
- 报错原因 (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker fr
- spring出现 Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marke问题
- Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definitio
- Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly
- Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly'
- Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly
- Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly
- Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly
- Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or rem
- Spring+Hibernate4 发生异常Turn your Session into FlushMode.COMMIT/AUTO...