-->
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: How do i prevent schema export placing contraints on F Keys?
PostPosted: Thu Mar 29, 2007 8:02 pm 
Newbie

Joined: Tue Dec 12, 2006 6:35 pm
Posts: 19
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Hibernate 3.2.2


Name and version of the database you are using:

MySQL 4.1.22

The generated SQL (show_sql=true):

Hibernate: select contact0_.id as id1_0_, contact0_.number as number1_0_, contact0_.email as email1_0_, contact0_.website as website1_0_ from CMS_Contact contact0_ where contact0_.id=?
Hibernate: delete from CMS_ContentItem_Company where id=?
Hibernate: delete from CMS_ContentItem_Classification where id=?
Hibernate: delete from CMS_ContentItem_Feedback where id=?
Hibernate: delete from CMS_ContentItem_ContentItem where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Feedback where id=?
Hibernate: delete from CMS_Entity where id=?
Hibernate: delete from CMS_ContentItem where id=?
2007-03-29 20:26:28,796 WARN httpWorkerThread-8141-1 - SQL Error: 1217, SQLState: 23000
2007-03-29 20:26:28,812 ERROR httpWorkerThread-8141-1 - Duplicate key or integrity constraint violation message from server: "Cannot delete or update a parent row: a foreign key constraint fails"
2007-03-29 20:26:28,843 ERROR httpWorkerThread-8141-1 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
......
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
Caused by: java.sql.BatchUpdateException: Duplicate key or integrity constraint violation message from server: "Cannot delete or update a parent row: a foreign key constraint fails"
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1540)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 74 more



Generated create statement from schema export:

CREATE TABLE `cms_contentitem` (
`id` int(11) NOT NULL auto_increment,
`active` tinyint(1) default NULL,
`status` int(11) default NULL,
`title` varchar(255) default NULL,
`description` text,
`feature` tinyint(1) default NULL,
`releaseDate` datetime default NULL,
`createdDate` datetime default NULL,
`createdBy` int(11) default NULL,
`modifiedDate` datetime default NULL,
`modifiedBy` int(11) default NULL,
`threadId` int(11) default NULL,
`imageName` varchar(255) default NULL,
`thumbnailName` varchar(255) default NULL,
`comments` varchar(255) default NULL,
`itemType` int(11) default NULL,
PRIMARY KEY (`id`),
KEY `FKEFBCD4F6F80E36A6` (`itemType`),
CONSTRAINT `FKEFBCD4F6F80E36A6` FOREIGN KEY (`itemType`) REFERENCES `cms_type` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1




I am getting a constraint error when trying to delete from this table.

Is their anything i can do to prevent schema export creating constraints?

_________________
_________________________
http://www.joshandfriends.com.au

Dance Music | Events | DJs


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 1:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
You should spend time figuring out why the constraint error occurs instead of removing the constraint. (constraints are a Good Thing)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 31, 2007 7:23 am 
Newbie

Joined: Tue Dec 12, 2006 6:35 pm
Posts: 19
Good point.

The magic line needed for mysql to show what constraint is failing and why is:

show innodb status


Hope that helps if anyone else has the problem

_________________
_________________________
http://www.joshandfriends.com.au

Dance Music | Events | DJs


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.