I'm having a problem with a pretty simple setup in NHibernate. (I'm using Fluent Nhibernate)
I have two objects as follows, setup with a bi-directional many-to-many mapping.
Project
-- Categories (IList)
Category
-- Projects (IList) -- Inverse = True
This models as expected in the db.
If I try to delete a project NHibernate performs the delete in the many-to-many table then deletes the project as expected.
However, if I try to delete a category 开发者_Python百科NHibernate throws an exception that it would violate a foreign key constraint.
I've experimentet with inverse="true" on both sides but the exception is thrown either when I try to delete a Project or a Category (depending on where inverse="true" is).If I remove inverse="true" from both sides the delete works as expected on either end. But this causes double entries when saving and updating.
Can anyone tell me where I am going wrong?
Is it possible that you're not synching up your entire object graph? The schema you show suggests that Project has a collection of Categories, and Category has a collection of Projects. Hibernate expects you to keep the associations in synch within your object graph. In order to delete a Category (for example), try first clearing its projects collection, and removing that category from the "categories" collections of any projects it was associated with.
精彩评论