in Java, Programming, Spring

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;

问题解决!

参考

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

Write a Comment

Comment