The explanation is pretty good for one-to-many "bidirectional" relationship. But what I am actually trying to do is a one-to-many "uni-directional" relationship with a "list" on many end. It is like this.
Code:
<class name="Parent" table="parents">
<key>
<column name="parent_id", sql-type="char(36)"/>
</key>
<list name="children" cascade="all-delete-orphan">
<key>
<column name="parent_id" sql-type="char(36)"/>
</key>
<index column="index"/>
<one-to-many class="Child"/>
</list>
</class>
<class name="Child" table="children">
<key>
<column name="child_id" sql-type="char(36)"/>
</key>
</class>
And in this, when I save a Parent instance the first time (using just session.saveOrUpdate( parent ); session.flush(); ), everything is fine.
But if I try to save the same Parent instance, with some modifications to the list of children using the same two above statements, then it gives me an exception saying "you may not dereference a collection with cascade="all-delete-orphan" option. If I change that option to just cascade="all", then it does save my Parent instance, but leaves behind any orphaned children in the childrens table.
If anyone can throw some light on the correct way of mapping this relation and also the steps (or method calls) to save or update such instances, I would appreciate. Just to note, all changes to my Parent instance (including adding/modifying/deleting children from the collection) are being done in a UI tier where I dont have the session instance.
Thanks