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!