问题描述:在某服务器上对用户信息做修改的时候出现这样的提示,之前并未出现异常,测试服以及其他服务器也并未出现异常,异常信息如下:
org.springframework.jdbc.UncategorizedSQLException:
### Error updating database. Cause: java.sql.SQLException: Statement violates GTID consistency: Updates to non-transactional tables can only be done in either autocommitted statements or single-statement transactions, and never in the same statement as updates to transactional tables.
### The error may involve com.mintel.teacher.mapper.MintMapper.updateUserextend-Inline
### The error occurred while setting parameters
定位的代码:在同一个事务中要对两张表update

日志中显示对第一张表的更新成功了,在对第二站表操作的时候进行了 roll back ,
然后查看数据库发现这两张表的 ENGINE分别为 InnoDB(第一张表)、MyISAM(第二张表),
InnoDB: Supports transactions, row-level locking, and foreign keys 即支持事务、行级锁和外键,而MyISAM是不支持事务的。
鉴于之前是未出现问题的,重点考虑数据库层面的问题,查看数据库 GTID 设置,命令:show global variables like '%GTID%';

在未使用主从的情况下,这两个设置应该是 OFF状态的(截图为修改后的结果),否则会出现这样提示:
Updates to non-transactional tables can only be done in either autocommitted statements or single-statement transactions,
and never in the same statement as updates to transactional tables.
对非事务性表的更新只能在自动提交语句或单语句事务中进行,而且永远不要在同一个语句中更新事务表。
更正确的操作应该是从数据库设计上、业务上进行优化,避免出现这样的情况,那就是另一个故事了。
在服务器上更新用户信息时遇到UncategorizedSQLException,问题源于同一事务中对InnoDB和MyISAM表的更新。InnoDB支持事务,而MyISAM不支持。检查发现GTID设置可能导致问题。解决方案包括优化数据库设计和事务处理方式,避免在相同语句中更新事务和非事务表。

被折叠的 条评论
为什么被折叠?



