These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: changing MySQL RESTRICT constraint created by SchemaExport?
PostPosted: Tue Jul 11, 2006 8:07 am 
Newbie

Joined: Thu Apr 06, 2006 1:17 am
Posts: 6
Location: Copenhagen, Denmark
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>



Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 1:04 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
you said you tried all sorts of cascade options, did you do all-delete-orphan?

Code:
  <bag name="Lines" table="tblOrderLines" lazy="true" cascade="all-delete-orphan">
    <key column="OrderId"/>
    <one-to-many class="TestApp.Data.OrderLine"/>
  </bag>


same error?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 6:53 am 
Newbie

Joined: Thu Apr 06, 2006 1:17 am
Posts: 6
Location: Copenhagen, Denmark
hmm.. yes, I also tried that with same result.

Actually I don't think it is related to the bag in the Order object, but rather the many-to-one relation in the OrderLines object, because if I remove this relation completely, it doesn't make any Foreign key in the table at all.

So I would believe that the many-to-one relation should have an option that controls/disable the constraints, but it doesn't allow me to set any cascade-options on this type of relation.

any ideas? Are there any new/upcoming mapping tools available which could help on clarifying this?

would it help if I posted a fully working test-application? (the code I posted was just a very simplified version of my actual case)


Top
 Profile  
 
 Post subject: Cascade Restrict NoAction Delete Parent/Child Relationship
PostPosted: Tue Oct 21, 2008 10:33 pm 
Newbie

Joined: Tue Oct 21, 2008 10:29 pm
Posts: 1
Hi I have experienced the same problem however I have a recursive relationship but still parent/child.

Did you solve this?

Thanks
Glenn


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.