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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yuzongtao/article/details/40919503

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

报错日志:
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>


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页