[jboss-user] [EJB 3.0] - Re: Problem with composite Primary key which is also a forei

imranpariyani do-not-reply at jboss.com
Mon Apr 23 11:43:40 EDT 2007


I think i dint explain my problem that well ... will do it again 

CREATE TABLE `parent` (
  `id` int(11) NOT NULL auto_increment,
  `sitename` varchar(40) NOT NULL,
  PRIMARY KEY  (`id`))

CREATE TABLE `child` (
  `parent_id` int(11) NOT NULL,
  `language` enum('EN,'DE','FR') NOT NULL default 'EN',
  PRIMARY KEY  (`parent_id`,`language`),
  CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 

so as you see the parent_id in the child is a part of composite primary key and also a forigen key .. 

so the childPk has the fileds parentId and language ... 
and the child class must have the same exact properties as the childPk class and these properties are annotated with multiple @Id annotations..

everything works fine .. like update delete insert .. there is only a prob when i try to insert a new parent .. with the child collection initialized .. 

If i first insert the parent with the child collection null and the insert the child collection after assigning the parent object which was inserted then it works fine .. but not if i insert new parent with child objects ... it throws this error of foreign key violation because it tries to insert the child with the foreign key parent id as 0 

Regards,

Imran


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4039900#4039900

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4039900



More information about the jboss-user mailing list