2 回答

TA貢獻1810條經驗 獲得超5個贊
您@OneToMany對IngredientsList類的注釋暗示類中應該有一個ingredientsList字段Ingredient,而實際上沒有。在您的架構中,您INGREDIENT_ID的ingredientsList表中有一個字段,這意味著 anIngredientsList只能有一個Ingredient.
我認為你的意思是IngredientsList有很多Ingredient孩子,這意味著ingredient表應該有一個INGREDIENT_LIST_ID字段作為ingredientsList表的外鍵,并且Ingredients類應該有一個ingredientsList字段。該INGREDIENT_ID字段應該從ingredientsList表中刪除。
如果一個IngredientsList應該只有一個Ingredient,那么改變
@OneToMany(mappedBy = "ingredientsList", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Ingredient> ingredients;
到
@ManyToOne
@JoinColumn("ingredient_id")
private Ingredient ingredient
根據需要添加cascade和orphanRemoval。@ManyToOne默認情況下,A應該急切地獲取連接的數據。
添加回答
舉報