apache / incubator-seata

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
https://seata.apache.org/
Apache License 2.0
25.35k stars 8.78k forks source link

SpringBoot 2.4 + SpringDataJpa + PostgreSQL 12.x + Identity主键的问题 #5746

Closed wnwnfgx closed 1 year ago

wnwnfgx commented 1 year ago

在Entity中的自增主键定义为

@Id @GeneratedValue(strategy= GenerationType.IDENTITY) private Long id;

Jpa会自动创建表的序列和主键Id列(类型为 serial8 )。SpringDataJpa在insert数据时不会写入id列的值,导致Seata AT模式在insert数据时报错 :io.seata.common.exception.ShouldNeverHappenException: pkIndex is not found

funky-eyes commented 1 year ago

跟你jpa插入没有id没什么关系,请确定你有没有主键

wnwnfgx commented 1 year ago

image 确定是有的

wnwnfgx commented 1 year ago

如果Entity中的id列定义成这样就没有问题,但太多地方要修改了,是否seata不支持postgresql的serial自增主键呢?使用的seata版本是1.6.1

@id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ms_people_seq") @SequenceGenerator(sequenceName = "ms_people_seq", name = "ms_people_seq", allocationSize = 1) private Long id;

funky-eyes commented 1 year ago

当时支持多主键上有个bug,导致不读自增主键,你尝试升级1.7看看