-
问题描述:
在使用repository.save()往数据库添加数据时,报id设置为空的错,但是我的id是使用自增主键注解了啊:@GeneratedValue(strategy = Generation.IDENTITY),为什么还会报错呢? -
解决方案:
由于数据表是其他人事先建好的,发现数据表并没有设置自增主键show create table xxx;
'id' is not null comment '自增id'
可以看到并没有设置自增:auto_increment
解决方法:
添加主键为自增alter table '表名' modify column id INT auto_increment
【数据库】使用JPA往数据库save时的坑
于 2023-11-03 14:26:10 首次发布