springcloud常见问题及解决
1. seata
1.1 Caused by: io.seata.common.exception.NotSupportYetException: aa_bb_record needs to contain the primary key.
seata 全局事务报业务表(postgresql 序列主键) 需要包含primary key
解决:
多数据源配置 seata.enable-auto-data-source-proxy=false
单个数据源配置 seata.enable-auto-data-source-proxy=true
seata.enable-auto-data-source-proxy=false
1.2 io.seata.common.exception.NotSupportYetException: undo_log needs to contain the primary key.
seata1.2.0 全局事务报undo_log 需要包含primary key
解决:
官方undo_log ddl 参考
加了自增id后的ddl如下:
CREATE TABLE `undo_log` (
`branch_id` bigint(20) NOT NULL COMMENT 'branch transaction id',
`xid` varchar(100) NOT NULL COMMENT 'global transaction id',
`context` varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization',
`rollback_info` longblob NOT NULL COMMENT 'rollback info',
`log_status` int(11) NOT NULL COMMENT '0:normal status,1:defense status',
`log_created` datetime(6) NOT NULL COMMENT 'create datetime',
`log_modified` datetime(6) NOT NULL COMMENT 'modify datetime',
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='AT transaction mode undo table'
1.3 java.sql.SQLException: Field ‘id’ doesn’t have a default value
异常主要堆栈
ERROR [main] i.s.r.d.ConnectionProxy.processGlobalTransactionCommit(224): process connectionProxy commit error: Field 'id' doesn't have a default value
java.sql.SQLException: Field 'id' doesn't have a default value
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1347)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
at io.seata.rm.datasource.undo.mysql.MySQLUndoLogManager.insertUndoLog(MySQLUndoLogManager.java:100)
at io.seata.rm.datasource.undo.mysql.MySQLUndoLogManager.insertUndoLogWithNormal(MySQLUndoLogManager.java:76)
解决:查看***分支事务***所在的数据源中的undo_log表,id是否设置为自增,设置为自增即可。