数据库报Connection is read-only. Queries leading to data modification are not allowed

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

数据库报Connection is read-only. Queries leading to data modification are not allowed,具体是某张表的插入操作时报的错误

问题排查过程:

     这个超过是批量操作发生的,第一反应是数据库是不是分读写库,但是单条插入的时可以成功入库,这个错误原因排除。

想到数据库的事务问题,有可能是配置了方法名称的限制,查文件果然是

<property name="transactionAttributes">
   <props>
	 <prop key="do*">PROPAGATION_REQUIRED,-Exception</prop>
	 <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
	 <prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>
	 <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
	 <prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
	 <prop key="complete*">PROPAGATION_REQUIRED,-Exception</prop>
	 <prop key="terminate*">PROPAGATION_REQUIRED,-Exception</prop>
	 <prop key="apply*">PROPAGATION_REQUIRED,-Exception</prop>
	 <prop key="cancel*">PROPAGATION_REQUIRED,-Exception</prop>
	 <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
   </props>
</property>

会发现最后一行有readOnly字段,它的意思是对所有的方法只能读,可能批量的方法没有在这里配置导致的。

修改:

1.将批量导入的方法配置一下

<prop key="batch*">PROPAGATION_REQUIRED,-Exception</prop>

2.如果应用功能较少,可以这样配置(不建议)

<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>

猜你喜欢

转载自blog.csdn.net/nanruitao10/article/details/84785481
今日推荐