Skip to content

1.6.1,pgsql自增主键、当insert语句不包含主键列时,报[ShouldNeverHappenException: pkIndex is not found] #5264

@isharpever

Description

@isharpever
  • I have searched the issues of this repository and believe that this is not a duplicate.

Ⅰ. Issue Description

seata1.6.1,AT模式,使用pgsql自增主键、且insert语句不包含主键列时,抛出异常[ShouldNeverHappenException: pkIndex is not found]

Ⅱ. Describe what happened

If there is an exception, please attach the exception trace:

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]

Ⅲ. Describe what you expected to happen

seata1.6.1,AT模式,使用pgsql自增主键、且insert语句不包含主键列时,不发生异常,insert执行成功。

Ⅳ. How to reproduce it (as minimally and precisely as possible)

如下是测试代码

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

Ⅴ. Anything else we need to know?

  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")
)
  1. 从seata1.6.0开始有问题(使用seata1.5.2测试,没有上述问题)

Ⅵ. Environment:

  • JDK version : 1.8.0_301
  • Seata version: 1.6.0、1.6.1
  • OS : win10
  • Others: pgsql server版本=14.1、客户端驱动版本=42.5.1

Metadata

Metadata

Assignees

Labels

task: help-wantedExtra attention is neededtype: bugCategory issues or prs related to bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions