(详解)Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session

昨天发现以前正常的功能报错了,错误日志如下:

报错日志:
Hibernate: select taxtypecon0_.ID as ID62_, taxtypecon0_.TAX_TYPE_NAME as TAX2_62_, taxtypecon0_.EXPRESSIONS as EXPRESSI3_62_, taxtypecon0_.CREATE_DATE as CREATE4_62_, taxtypecon0_.CREATED_BY as CREATED5_62_, taxtypecon0_.LAST_UPDATE_DATE as LAST6_62_, taxtypecon0_.LAST_UPDATED_BY as LAST7_62_, taxtypecon0_.type_kind as type8_62_, taxtypecon0_.VALID_DATE_START as VALID9_62_, taxtypecon0_.VALID_DATE_END as VALID10_62_, taxtypecon0_.IS_VALID as IS11_62_ from tb_TAXTYPE_CONFIG taxtypecon0_ where (taxtypecon0_.type_kind=1 ) order by taxtypecon0_.CREATE_DATE desc
Hibernate: select taxtypecon0_.ID as ID62_, taxtypecon0_.TAX_TYPE_NAME as TAX2_62_, taxtypecon0_.EXPRESSIONS as EXPRESSI3_62_, taxtypecon0_.CREATE_DATE as CREATE4_62_, taxtypecon0_.CREATED_BY as CREATED5_62_, taxtypecon0_.LAST_UPDATE_DATE as LAST6_62_, taxtypecon0_.LAST_UPDATED_BY as LAST7_62_, taxtypecon0_.type_kind as type8_62_, taxtypecon0_.VALID_DATE_START as VALID9_62_, taxtypecon0_.VALID_DATE_END as VALID10_62_, taxtypecon0_.IS_VALID as IS11_62_ from tb_TAXTYPE_CONFIG taxtypecon0_ where (taxtypecon0_.ID=101 )
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.
    at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1186)
    at org.springframework.orm.hibernate3.HibernateTemplate$16.doInHibernate(HibernateTemplate.java:750)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
    at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:748)
    at com.linkage.framework.pub.dao.BaseDao.saveOrUpdate(BaseDao.java:65)
    at com.linkage.budgetNew.cform.dao.impl.TaxtypeConfigDaoImpl.saveTaxtype(TaxtypeConfigDaoImpl.java:33)
    at com.linkage.budgetNew.cform.service.impl.TaxtypeConfigServiceImpl.saveTaxtype(TaxtypeConfigServiceImpl.java:24)
    at com.linkage.budgetNew.cform.service.impl.TaxtypeConfigServiceImpl$$FastClassByCGLIB$$766ec933.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
    at com.linkage.budgetNew.cform.service.impl.TaxtypeConfigServiceImpl$$EnhancerByCGLIB$$aa2803a3.saveTaxtype(<generated>)
    at com.linkage.budgetNew.cform.action.TaxTypeConfigAction.saveTaxType(TaxTypeConfigAction.java:53)
	

DEBUG调试发现在DAO层调用saveOrUpdate()方法时报错
public void saveTaxtype(TaxtypeConfig TaxtypeConfig)
{
    saveOrUpdate(TaxtypeConfig);
}

对比日志说的:

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.

知道是配置Hibernate事务管理有问题,果然发现下面这行被别人误删掉了,加上这句话就OK了。

<tx:method name="save*" rollback-for="Exception" propagation="REQUIRED"/>
没有这一行,事务管理默认走最下面的

<tx:method name="*" propagation="SUPPORTS" read-only="true" />
这样就无法进行“写操作”了:
 Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)

<!-- 事务管理 -->
	<tx:advice id="txAdvice2" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="do*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="save*" rollback-for="Exception" propagation="REQUIRED"/>
            <tx:method name="del*" propagation="REQUIRED" rollback-for="Exception" />
            <tx:method name="mod*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="ins*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="upd*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="invoke" propagation="REQUIRES_NEW" rollback-for="Exception" />
			<tx:method name="*" propagation="SUPPORTS" read-only="true" />
		</tx:attributes>
	</tx:advice>


  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值