org.springframework.dao.TransientDataAccessResourceException:
### Error updating database. Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
### The error may involve com.segi.uhomecp.charging.api.accrualBasis.dao.BillAccrualBasisCycleMapper.insertBatch-Inline
### The error occurred while setting parameters
### Cause: java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
; SQL []; Connection is read-only. Queries leading to data modification are not allowed; nested exception is java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:106)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy17.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:278)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:79)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
at com.sun.proxy.$Proxy23.insertBatch(Unknown Source)
...
只读权限,一般如果报了这个错,是项目中事务配置文件的问题。
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
<tx:method name="delete*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="register*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="insert*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="create*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="proccess*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="register*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="handler*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="add*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="load*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="onApplicationEvent*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="generateSequence*" propagation="REQUIRED" rollback-for="java.lang.Exception" />
<tx:method name="doNew*" propagation="REQUIRES_NEW" rollback-for="java.lang.Exception" />
<tx:method name="selectNew*" propagation="REQUIRES_NEW" rollback-for="java.lang.Exception" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
因为事务是配置在service层,因此检查了我service层接口的代码,发现方法名是query开头的,service调用的query方法根本就没有事务。
问题原因找到了,解决办法也很简单,修改接口名称(跟配置文件中匹配即可)