Error updating database. Cause: java.sql.SQLException: Connection is read-only. Queries leading to

       最近公司一个老项目,更新数据库报这个错误。一般是方法名字不对(配置里面设置了,比如说,方法名字中带有get的,不让修改数据)。

   

    <aop:config <aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice"/> </aop:config> <!-- 事务的传播特性 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" propagation="REQUIRED" read-only="true"/> <tx:method name="find*" propagation="REQUIRED" read-only="true"/> <tx:method name="query*" propagation="REQUIRED" read-only="true"/> </tx:attributes>

    <aop:config <aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice"/>

    </aop:config> <!-- 事务的传播特性 -->

<tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes>

<tx:method name="get*" propagation="REQUIRED" read-only="true"/>

<tx:method name="find*" propagation="REQUIRED" read-only="true"/>

<tx:method name="query*" propagation="REQUIRED" read-only="true"/> </tx:attributes>

比如说上面这种配置,就是方法里面包含有get、find、query的(以这个开头的),就会默认你是查询,如果你这个方法其实是更新数据,那就报错了。所以解决办法就是,如果你是更新数据的方法,那就不要出现get、find、query,另外起一个别的名字。

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
这个错误通常是由于数据库约束引发的。在引用和中可以看到,错误的原因是主键冲突和某个列值为空。这可能是由于在插入数据时,违反了数据库表的主键约束或者某个列字段的非空约束。具体来说,在引用中,错误可能是由于尝试插入一个空值到`click_count`列引起的。而在引用中,错误可能是由于尝试插入一个已经存在的主键值引起的。 要解决这个问题,你可以检查你的代码和数据库表定义,确保插入的数据满足表的约束条件。在你的情况中,你已经发现了问题所在,即在`GoodsServiceImpl`中应该使用`insertSelective`方法而不是`insert`方法。`insertSelective`方法只会插入非空字段,而`insert`方法会插入所有字段,可能导致某些字段为空。123 #### 引用[.reference_title] - *1* *3* [Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry](https://blog.csdn.net/weixin_41997327/article/details/115418631)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *2* [Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Column ‘click_co](https://blog.csdn.net/m0_48044456/article/details/116955601)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值