0
votes

I have parent+child relationship and child collection is mapped as lazy. I fetch a parent, and of course because of the lazy loading child collection is not loaded. But when I want to update my parent NH first loads child collection. I'm interesting is this by default, or I went wrong somewhere. Collection is lazy, inverse=true and cascade="all-delete-orphan". I assume that because of cascade mapping NH wants to check changes on the child collection and it is accessed for the first time so lazy load did it's job. Please can somebody confirm this.

1

1 Answers

0
votes

When updating the parent object NHibernate should not have to load the child collection unless you are modifying the foreign key relationship column.

Inverse="true" This means that the objects in the child collection are responsible for managing the relationship with the parent.

cascade="all-delete-orphan" When adding a new child object to the collection it will cascade to the DB without you having to explicitly call Session.Save(childobj) first. It also means if you delete the parent object all of the child collection object will also be deleted from the DB.

I use those exact settings for my child collection relationships and do not see this behaviour.

Could you post your mappings/fluent maps/test code which may give more insight into the issue at hand?