2 回答

TA貢獻1840條經(jīng)驗 獲得超5個贊
您在 Bestellingsregel 將 Bestelling 和 Bestellingsregel 之間的關(guān)系定義為與擁有方(持有外鍵)的雙向關(guān)系,這是正確的,但有利也有弊。
您有以下選擇:
使用定義的關(guān)系并將 Bestelling 對象設(shè)置為列表中的每個 Bestellingsregel 對象。Bestellingsregel 是擁有方,因此您必須在保存前直接設(shè)置參考。
使您的關(guān)系單向:從 Bestellingsregel 中刪除 Bestelling 參考并重新定義我們的
@OneToMany
關(guān)系
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, , orphanRemoval = true)
@JoinColumn(name = "bestelling_id")
private List<Bestellingsregel> bestellingsregels = new ArrayList<>();

TA貢獻1820條經(jīng)驗 獲得超10個贊
Bestelling b = new Bestelling();
Bestellingsregel br = new Bestellingsregel();
br.setBestelling(b);
List<Bestellingsregel> list = new ArrayList<>();
list.add(br);
b.setBestellingsregels(list);
repo.save(b);
這對我有用。我猜你沒有在 Bestellingsregel 對象中設(shè)置 Bestelling 對象。
添加回答
舉報