-->
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.  [ 3 posts ] 
Author Message
 Post subject: SchemaExport table drops fails due to foreign key constraint
PostPosted: Tue May 25, 2004 6:34 pm 
Newbie

Joined: Mon May 10, 2004 5:40 pm
Posts: 3
Hi,

SchemaExport may choose an order for table drops which can result in failure due foreign key constraints.

Assume there exists table category and table item. Table item has category_id as a foreign key. SchemaExport may attempt to drop table category before table item which fails. MySQL, for example will complain of ERROR 1217: Cannot delete or update a parent row: a foreign key constraint fails.

Is there any way to control the order in which SchemaExport drops tables? or maybe it could be a little smarter in choosing the order itself?

Alex


Top
 Profile  
 
 Post subject: Re: SchemaExport table drops fails due to foreign key constr
PostPosted: Wed Jul 21, 2004 6:16 am 
Newbie

Joined: Wed Feb 11, 2004 5:08 am
Posts: 14
lvitup wrote:
SchemaExport may choose an order for table drops which can result in failure due foreign key constraints.

Assume there exists table category and table item. Table item has category_id as a foreign key. SchemaExport may attempt to drop table category before table item which fails. MySQL, for example will complain of ERROR 1217: Cannot delete or update a parent row: a foreign key constraint fails.

Is there any way to control the order in which SchemaExport drops tables? or maybe it could be a little smarter in choosing the order itself?

Alex


I'm having exactly the same problem with PostgreSQL. Is there any workaround available? Is this feature planned to be implemented in the future?


-Jouni Hartikainen


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 10:52 pm 
Newbie

Joined: Tue May 25, 2004 12:18 am
Posts: 4
I've got around this by adding :

if(dialect instanceof MySQLDialect){
script.add("SET FOREIGN_KEY_CHECKS=0");
}

to generateDropSchemaScript() in net.sf.hibernate.cfg.Configuration and rebuilding Hibernate. Any chance a getDropSchemePrelude() method or similar could be added to the Dialect class and of course to the MySQL dialect?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.