When deleting an object (an Order containing OrderLines), I get the following exception from a constraint in the OrderLines table:
#23000Cannot delete or update a parent row: a foreign key constraint fails (`testapp/tblOrderLines`, CONSTRAINT `FK10FBF332C4A97B1D` FOREIGN KEY (`OrderId`) REFERENCES `tblOrders (`OrderId`))
In my mapping below, besides the "normal" bag parent/child relation, I also have an opposite relation from the OrderLine to the Order, so I can access the Order from the OrderLine, which causes the constraint to be created.
I use the SchemaExport tool to generate the MySQL tables, but I can see in the MySQL table that it has generated foreign keys with "On Delete" constraint set to "Restrict", so a Delete operation on the Order object will always fail. How can I change this constraint to "No action" or "Cascade"?
Do I miss something in my mapping for this? I tried to set all kinds of cascade-options in the mapping with no difference.
I use NHibernate 1.02
Code:
<class name="TestApp.Data.Order" table="tblOrders">
<id name="HbId" column="OrderId" type="Int64" unsaved-value="0" access="field">
<generator class="hilo"/>
</id>
<bag name="Lines" table="tblOrderLines" lazy="true">
<key column="OrderId"/>
<one-to-many class="TestApp.Data.OrderLine"/>
</bag>
</class>
<class name="TestApp.Data.OrderLine" table="tblOrderLines">
<id name="HbId" column="OrderLineId" type="Int64" unsaved-value="0" access="field">
<generator class="hilo"/>
</id>
<many-to-one name="Order" column="OrderId" class="TestApp.Data.Order"/>
</class>