What would be the correct and easy way to update a collection if it is mapped to all-delete-orphan by its parent?
When updating, I do not want to just add / remove elements from the collection, but also update the values โโof the properties of the element (of course, for those elements that were previously in the collection).
In the script there is an object Parent
in which there are collections of objects Child
, and there is one form with which users can edit the Children collection - add / remove children, as well as edit the properties of children (in the same form).
Basically, I want something like this:
Parent parent = session.get(Parent.class, parentUI.getId());
parent.setChildren(parentUI.getChildren());
session.saveOrUpdate(parent);
This does not work, and I understand the reasons for this, but it seems to me that this should be a very common situation when using sleep mode and developing user interface applications, so I'm looking for a solution (from the book).
I am using hibernate 3.6.10 and XML based configuration.
Here's the matching mapping (I use ArrayList to store a collection of children):
<list name="children" cascade="all, delete-orphan">
<key column="parent_id" not-null="true"/>
<list-index column="ordinal" />
<one-to-many class="Child" />
</list>
If that matters, the child objects also have associated collections in the same way, but I do not find this relevant, as this is a problem equal to that described.
Btw. I lost the whole day on this and, of course, checked dozens of very similar questions, but did not find a reasonable solution or template to solve this. Perhaps I missed something?