Hi,
I mapped a class as a component so it gets deleted whenever the parent (MyClass) is deleted (see mapping below). So far this works.
The component itself contains a collection of objects (the bag).
Code:
<class name="MyClass">
...
<component
name="myComponent"
access="field"
insert="true"
update="true"
lazy="false">
<bag
name="something"
access="field"
lazy="false"
cascade="all-delete-orphan">
<key column="MyClass_id" />
<one-to-many class="Something" />
</bag>
</component>
</class>
Whenever I delete a MyClass object, the component is removed and the collection as well. Exactly what I wanted!
Now what doesn't work is the following:
Code:
MyClass myObject; // comes from the database
myObject.setMyComponent(someNewComponent); // set new component with a new something collection
saveOrUpdate(myObject); // Throws A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance
Is there a way to get this collection deleted? If not, that means I can never replace the component with a new instance. If that is the case, is there an alternative mapping for this situation?
Thanks!
Bert.