[seata]SpringBoot 2.4 + SpringDataJpa + PostgreSQL 12.x + Identity主键的问题

2024-01-04 450 views
0

在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

回答

9

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

3

image 确定是有的

1

如果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;

1

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