Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have been struggling with the same thing. Reaction is a bit late, but maybe future readers can benefit.</p> <p>The solution of allowing null as foreign key on the child table works, but it might not be desirable from a database design point of view if your child cannot exist without a parent anyway. Modifying the database design purely because NHibernate requires it, is not something I prefer. Also changing from bidirectional to unidirectional was undesirable for me. So I dove in and tried all sorts of combinations of mappings.</p> <p>What I found out is that using inverse = true fixed the problem. First I thought this was bad behavior from NHibernate, since inverse = true is mostly explained as making the child collection responsible for the relation, which I thought I already covered by manually updating both child and parent. But this responsibility is more of a database thing than anything else.</p> <p>Using inverse = true, it is still possible to delete a child by removing it from the parent, as long as you have Cascade.AllDeleteOrphan on the parent-side of the mapping, everything will be correctly updated. If you choose to use Cascade.All, you must also explicitly delete the child.</p> <p>If the parent is not loaded you can also choose to delete the child immediately, simply by deleting it in the current session. But this does not work if the parent is loaded in which case it will give the cascade re-save issues.</p> <p>Bottom line for me is, inverse works. And I have not found a scenario in which inverse = false gives me better results, but I might get back to that opinion once diving deeper into NHibernate.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload