-->
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: Cascading breaks if parent table doesn't have Auto-inc
PostPosted: Thu Jun 05, 2008 10:16 am 
Newbie

Joined: Tue Dec 18, 2007 2:06 pm
Posts: 9
Consider:

- a table with an assigned PK (i.e. not auto-increment), let's call this "A"
- Another table ("B") linked to the table listed above but with it's PK set to auto-increment.

Now if you try to save B with cascading switched on, it will break. From the little debugging I've done it looks like:

a) hibernate detects that A needs to be saved first, but puts it into some sort of queue.
b) when it hits B, it short-circuits this save queue and tries to save B immediately so as to obtain a PK reference for B. This fails since A hasn't been yet been saved so it's link is still null.

Can anyone please confirm this before I open a Jira issue?

Thanks.


Schema used is listed below (MySQL):
----

CREATE DATABASE `jira` /*!40100 DEFAULT CHARACTER SET latin1 */;

DROP TABLE IF EXISTS `jira`.`parent`;
CREATE TABLE `jira`.`parent` (
`parent_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `jira`.`child`;
CREATE TABLE `jira`.`child` (
`child_id` int(10) unsigned NOT NULL auto_increment,
`parent_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`child_id`),
KEY `FK_child_1` (`parent_id`),
CONSTRAINT `FK_child_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`parent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-----

P.S. Tested this with versions 3.2.5, 3.2.6 and 3.3


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.