【发布时间】:2021-05-23 15:54:33
【问题描述】:
我在 Spring Boot 中有我的 api。
我有 2 节课:
这是我的供应商类:
public class Supplier{
@OneToMany(cascade= {CascadeType.ALL})
private List<Product> products; <--- This one is working perfectly fine.
@OneToMany(cascade= {CascadeType.ALL})
private List<Ingredient> components; <---- this is the line where I am getting an error
}
这是我收到的错误消息:
“一对多”属性值类型不应为“成分”
这是我的成分类
public class Ingredient {
@Id
@GeneratedValue
private Long id;
private String name;
private String unit;
private Double quantity = 0.0;
private Double cost = 0.0;
private Double price = 0.0;
}
我的问题: 上述错误的可能解决方法是:
private List<Ingredient> components;
即使它上面的那行是有效的?
【问题讨论】:
-
假设
Supplier也是一个实体,那么请您告诉Ingredient实体中的哪一列定义了与Supplier实体的这种关联。您需要使用该列名称和附加注释@JoinColumn(name = "<foreignKey>")
标签: java spring spring-boot spring-mvc spring-data-jpa