-->
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.  [ 1 post ] 
Author Message
 Post subject: Set null on delete of one to one relationship
PostPosted: Thu Jul 19, 2007 2:05 am 
Newbie

Joined: Sun Apr 29, 2007 4:27 am
Posts: 10
Location: Israel
hibernate 3.2.1 w\ MySql

I’m having problem with the way hibernate manages one-to-one relationship.
Before starting, some history regarding the problem:

http://opensource.atlassian.com/project ... e/HHH-2707\
http://opensource.atlassian.com/project ... e/HHH-2007

As far as I’m concern, when creating a new one to one relationship between ‘myTable’ and ‘My otherTable’, the creation SQL will define the constraints ‘on delete’ default to ‘restrict’

SQL creation command example:
Code:
CREATE TABLE  `myDb`.`myTable` (
  `id` varchar(255) NOT NULL,
  . . .
  PRIMARY KEY  (`id`),
  KEY `FK5B7C41CE8DCFFD38` (`myOtherTable_id`),
  CONSTRAINT `FK5B7C41CE8DCFFD38` FOREIGN KEY (`myOtherTable_id `) REFERENCES `myOtherTable` (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

That causes be a lot of troubles when trying to remove myOtherTable instance.

A lot of problems example:
Code:
SQL Error: 1451, SQLState: 23000
Cannot delete or update a parent row: a foreign key constraint fails (`myDb/myTable `, CONSTRAINT ` FK5B7C41CE8DCFFD38` FOREIGN KEY (`myOtherTable_id`) REFERENCES ` myOtherTable` (`id `))

A good solution here will be to change the constraint ‘on delete’ default to ‘set null’, yet, I didn’t find a way to make hibernate to do this for me. The only options as I can see that are
a) To manage the delete by my own .
b) To create my DB alone.

Any better solutions?

G’day!


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

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.