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
- 上面例子里面,pgsql自增主键表hello的建表语句如下:
CREATE TABLE "hello" ( "id" serial4 NOT NULL, "name" varchar(32) COLLATE "pg_catalog"."default" NOT NULL, CONSTRAINT "hello_pkey" PRIMARY KEY ("id") )
- 从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