kochcp wrote:
bluesky wrote:
So there is a way to implement a custom delete using hibernate with the standard one-to-many mapping, so I can just call session.delete(Category) and it won't delete the item? I am not clear what you are suggesting
sorry for being unclear. there is no need to try to customize session.delete to mimic your exact functionality. Write your own delete function. Don't be bound on trying to have hibernate methods do what you need to do.
[code]
public void customDelete (Category cat) {
List items = cat.getItems();
(Iterate over items) {
item1.setInactive();
item1.setCategory(null);
session.merge(item1);
}
//if you actually wanna delete the category, then use your session.delete
session.delete(cat);
}
Chris- I see what you mean now. My big concern with this was that when I do a session.delete(category) it will automatically delete the item. So to avoid this would I just set cascade="save-update" like so:
<class name="Category" TABLE="CATEGORIES">
<id name="id" column="ID" type="int" unsaved-value="-1">
<generator class="identity"/>
</id>
<property name="name" column="NAME" not-null="true"/>
<set name="items" cascade="save-update">
<key column="CATEGORY_ID"/>
<one-to-many class="Item"/>
</set>
</class>
So now I can go:
category.getItems().remove(item);
item.setInactive(true);
item.setCategory(null);//IS THIS NECESSARY or will it automatically do this?
session.save(item);
session.delete(cat);