![](/img/trans.png)
[英]Hibernate saveorupdate or merge for saving/updating one-to-many relationship objects
[英]hibernate one-to-many relationship not updating correctly
我有兩個表Item和Property,一個項目可以具有多個屬性。 我已經在休眠模式下正確建模(我認為),並且在加載ItemModel對象時,所有屬性均正確加載。
問題是當我嘗試刪除屬性然后將其保存時,這些屬性只是被添加到現有屬性中。
ItemModel m = ...;
m.getPropertySet().size() // returns 5 initially
m.getPropertySet().clear();
// some update function which adds properties
m.getPropertySet().size(); // returns 1
...currentSession().saveOrUpdate(m);
現在發生的情況是,該數據庫現在具有該類別的6個屬性,而不是1個。我應該怎么做才能使其工作?
Item映射到屬性的模型看起來像這樣
<set name="propertySet" cascade="all">
<key column="item_id" not-null="true"/>
<one-to-many class="Property"/>
</set>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.