If i create a new Parent object and then add new child object to it and attempt to do ISession.Merge(parent) I get “No row with the given identifier exists” exception for child object.
Isn’t Merge suppose to create a persistent object if it’s not found in DB? It only creates it if I merge the parent with an empty child collection.
Maybe something is wrong in my mappings?
I have this at child:
<many-to-one class="Parent fetch="join" name="Parent">
<column name="ParentId" />
</many-to-one>
And this at parent:
<bag fetch="join" inverse="true" lazy="false" name="Childs" mutable="true">
<key>
<column name="ParentId" />
</key>
<one-to-many class="Child" />
</bag>
You may use
cascadeor merge the child separately:Merging the children separately:
I’m actually not sure what happens if the children are already in the session cache but the parent is not. You probably need to build an instance with all the merged data yourself.