首页 > 解决方案 > Hibernate '必须在调用 save() 之前手动分配此类的 id' 但映射的数据已经包含 id

问题描述

使用 Spring Data Rest、Hibernate ORM 和 PostgreSQL。

我正在接收上传的电子表格,其中包含来自/upload路线的数据并将其映射到Product.class. 当电子表格被处理并映射到我Product.class并传递Product.class给我时,productRepo.save(product)我收到此错误消息

org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():

Product.class使用这些注释创建

@Data
@Entity
@Table(name="prd")
public class Product {

@Id
private Integer nbrSupCmbndKey;

nbr_sup_cmbnd_key是数据库中的主键列,此数据通过上传提供给我(我不需要自动生成此字段)

如何配置休眠使其正确保存,因为Product.class当我去执行此信息时,此信息已包含在映射中productRepo.save(Product)

标签: postgresqlhibernatespring-data-jpa

解决方案


推荐阅读