Hi,
This is consistent with the documentation, which states (in section 17.2):
Quote:
...
NHibernate would issue two SQL statements:
an INSERT to create the record for c
an UPDATE to create the link from p to c
This is not only inefficient, but also violates any NOT NULL constraint on the parent_id column.
Adding the code to set the parent property prevents the two-stage update (remember to set your inverse="true" property on your bag mapping). NHibernate can track the inverse relationship for you, but it uses the two-stage update described above, so your foreign-key needs to be nullable.
Quote:
This seems extremely verbose to me ...
Unless I'm missing something, there's only one extra line of code required to maintain the inverse relationship (coDetail.Company = co;). This is hardly 'extremely verbose'.
NHibernate's job is to persist (and restore) objects the same way that they would be held in memory. If you were writing the above code without a database and running entirely in memory, the same code to populate the inverse relationship would be required.
Hope that helps to clarify.
Regards,
Richard