try to change the cascade property of your mapping file to cascade="all-delete-orphan" Plácido Bisneto
2009/6/10 Ahmed Emad <[email protected]> > > hi > i have many to many association betwwne 2 entities : > > <class name="Item" table="Item" lazy="false" > > <id name="Id" column="Id" type="Int32"> > <generator class="native"/> > </id> > <property name="ItemName" column="ItemName" type="String" /> > <property name="InitialPrice" column="InitialPrice" > type="Int64" /> > <set name="Categorys" table="Item_Category" lazy="true" > cascade="save-update"> > <key> > <column name="ItemId"/> > </key> > <many-to-many class="Category"> > <column name="CategoryId"/> > </many-to-many> > </set> > </class> > > > > <class name="Category" table="Category" lazy="false" > > <id name="Id" column="Id" type="Int32"> > <generator class="native"/> > </id> > <property name="CategoryName" column="CategoryName" > type="String" /> > <property name="CategoryDesc" column="CategoryDesc" > type="String" /> > <set name="Items" table="Item_Category" lazy="true" > inverse="true" > cascade=""> > <key> > <column name="CategoryId"/> > </key> > <many-to-many class="Item"> > <column name="ItemId"/> > </many-to-many> > </set> > </class> > > > the problem appear when i try to delete item or category i get an > error : > > could not delete: [NHibernateFinalTest.Entities.Category#13][SQL: > DELETE FROM Category WHERE Id = ?] > > inner exception : {"The DELETE statement conflicted with the REFERENCE > constraint \"FK_Category_Item_Category\". The conflict occurred in > database \"FinalDbTest\", table \"dbo.Item_Category\", column > 'CategoryId'.\r\nThe statement has been terminated."} > > any one has help? > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
