Spring Data JPA返回ids for this class must be manually assigned before calling save()错误

小结

Spring Data JPA返回ids for this class must be manually assigned before calling save()错误,进行了解决。

问题及解决

Spring Boot应用存入数据时返回以下错误:

{"errorCode":"INTERNAL_ERROR","message":"ids for this class must be manually assigned before calling save(): ...","status":500,"timestamp":"2024-06-16T21:22:46.4322143"}

具体错误也就是插入数据时ID的主键没有人为指定赋值,需要指定合适的生成策略。

由以下代码:

    @Id
    @Column(name = "FILEID", nullable = false)
    private Integer id;

添加 @GeneratedValue(strategy = GenerationType.IDENTITY), 修改为以下:

    @Id
    @Column(name = "FILEID", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

问题解决!

参考

优快云: spring data jpa报错ids for this class must be manually assigned before calling save()
优快云: ids for this class must be manually assigned before calling save(): me.zhengjie.modules.system.domai

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值