问题描述
seata1.6.1,AT模式,使用pgsql自增主键、且insert语句不包含主键列时,抛出异常[ShouldNeverHappenException: pkIndex is not found]
2023-01-28 11:05:50.316 ERROR 24928 --- [nio-8082-exec-4] i.s.r.d.exec.AbstractDMLBaseExecutor : execute executeAutoCommitTrue error:pkIndex is not found
io.seata.common.exception.ShouldNeverHappenException: pkIndex is not found at io.seata.rm.datasource.exec.BaseInsertExecutor.parsePkValuesFromStatement(BaseInsertExecutor.java:142) ~[seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.exec.postgresql.PostgresqlInsertExecutor.getPkValuesByColumn(PostgresqlInsertExecutor.java:70) ~[seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.exec.postgresql.PostgresqlInsertExecutor.getPkValues(PostgresqlInsertExecutor.java:65) ~[seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.exec.BaseInsertExecutor.afterImage(BaseInsertExecutor.java:78) ~[seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor.executeAutoCommitFalse(AbstractDMLBaseExecutor.java:98) [seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor.lambda$executeAutoCommitTrue$2(AbstractDMLBaseExecutor.java:137) [seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.ConnectionProxy$LockRetryPolicy.doRetryOnLockConflict(ConnectionProxy.java:356) ~[seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor$LockRetryPolicy.execute(AbstractDMLBaseExecutor.java:180) ~[seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor.executeAutoCommitTrue(AbstractDMLBaseExecutor.java:136) [seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.exec.AbstractDMLBaseExecutor.doExecute(AbstractDMLBaseExecutor.java:82) [seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.exec.BaseTransactionalExecutor.execute(BaseTransactionalExecutor.java:125) [seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.exec.ExecuteTemplate.execute(ExecuteTemplate.java:137) [seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.exec.ExecuteTemplate.execute(ExecuteTemplate.java:56) [seata-all-1.6.1.jar:1.6.1] at io.seata.rm.datasource.PreparedStatementProxy.executeUpdate(PreparedStatementProxy.java:65) [seata-all-1.6.1.jar:1.6.1] at org.springframework.jdbc.core.JdbcTemplate.lambda$update$0(JdbcTemplate.java:867) [spring-jdbc-5.2.13.RELEASE.jar:5.2.13.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617) [spring-jdbc-5.2.13.RELEASE.jar:5.2.13.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:862) [spring-jdbc-5.2.13.RELEASE.jar:5.2.13.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:917) [spring-jdbc-5.2.13.RELEASE.jar:5.2.13.RELEASE] at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:927) [spring-jdbc-5.2.13.RELEASE.jar:5.2.13.RELEASE] at com.example.Demo.doWithGlobalTraction(Demo.java:17) ~[classes/:na]
期待结果
seata1.6.1,AT模式,使用pgsql自增主键、且insert语句不包含主键列时,不发生异常,insert执行成功。
如何复制
如下是测试代码
import io.seata.spring.annotation.GlobalTransactional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Component;
@Component public class Demo {
@Autowired
private JdbcTemplate jdbcTemplate;
@GlobalTransactional
public void doWithGlobalTraction(String name) {
// 向pgsql的自增主键表hello插入一条数据
// insert语句不包含主键列: id
jdbcTemplate.update("insert into hello(name) values(?)", name);
}
}
demo传送门:https://github.com/isharpever/seata-demo.git
其他信息:
1、上面例子里面,pgsql自增主键表hello的建表语句如下:
CREATE TABLE "hello" ( "id" serial4 NOT NULL, "name" varchar(32) COLLATE "pg_catalog"."default" NOT NULL, CONSTRAINT "hello_pkey" PRIMARY KEY ("id") )
2、从seata1.6.0开始有问题(使用seata1.5.2测试,没有上述问题)
环境信息
JDK version : 1.8.0_301 Seata version: 1.6.0、1.6.1 OS : win10 Others: pgsql server版本=14.1、客户端驱动版本=42.5.1
原提问者GitHub用户isharpever
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。