Hibernate version: 1.2.0.GA
I am trying to delete an entity which is in a child collection of another entity. For example, I am trying to delete a ContactAddress entity, which is a member of a Contact entity's Addresses collection.
I do this:
Code:
// At this point, myContactAddress.Contact = myContact
// We've set this up so that removing an entity from a collection
// automatically nulls out the appropriate "parent" property;
// in this case, it's ContactAddress.Contact
myContact.Addresses.Remove(myContactAddress);
// At this point, myContactAddress.Contact = null
mySession.Delete(myContactAddress);
This executes OK, but when the session is flushed, I get a SQL error about NHibernate trying to update the contact address row with a null value for the contact ID foreign key column. Buty since I called ISession.Delete() on myContactAddress, it shouldn't consider it for updating (or re-inserting) even if it appears "dirty". Doesn't it know it's marked as deleted? This sounds like a bug to me ...
We really don't want to disable the automatic maintenance of parent property values in our collections when items are added and removed, so it isn't an option on our end to try working around it by preventing the entity being deleted from getting "dirty". (If we don't remove it from the parent's collection, we get an exception that the deleted entity would be resaved by an update ...)