Thanks Fabio, my problem was not that I wanted a third solution but
that I did not understand what on-delete="cascade" actually did. I
could not find any defintion of this property in the on-line reference
section 6.3. Collections of Values and Many-To-Many Associations. Now
you have explained it I do understand it, and its implications, so I
will use it.
I would suggest that the documentation is updated to include this
property and that the text related to my original post updated to
explain that list.Clear() also depends on database RI CASCADE DELETE
to work. In fact the text:
"Occasionally, deleting collection elements one by one can be
extremely inefficient. NHibernate isn't completely stupid, so it knows
not to do that in the case of an newly-empty collection (if you called
list.Clear(), for example). In this case, NHibernate will issue a
single DELETE and we are done! "
suggests that NHibernate will do the behaviour I expected (issue a
DELETE FROM AssetContent WHERE contentID = ?" whereas in fact from my
tests, it doesn't. This code:
newContent.Assets.Clear();
Session.Delete(newContent);
(where newContent.Assests is an IList<IAsset> mapped to the bag)
appears to remove the collection objects from the session so
NHibernate no longer knows about them - therefore no delete occurs for
these. Without database CASCADE the code will crash.
I'm happy to update the documentation for you but I do not know how
gain access to it or if this is something you would allow.