• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Hibernate and Composite Foreign Keys

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone!

I was playing around with Hibernate for a little while. I'm just a rookie.
Everything went ok until I got into the need for some very basic but specific thing to be done that i couldn't ... so I'm asking you guys if it is true what I read in some forums that this behaviour is not fully supported by hibernate right now.

Here is the thing.
Suppose I have the following tables:

CREATE TABLE `proyect` (
`proyectId` int(10) unsigned NOT NULL,
`name` varchar(45) DEFAULT NULL,
PRIMARY KEY (`proyectId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `color` (
`proyectId` int(10) unsigned NOT NULL,
`colorId` int(10) unsigned NOT NULL,
`name` varchar(30) DEFAULT NULL,
PRIMARY KEY (`proyectId`,`colorId`),
CONSTRAINT `color_ibfk_1` FOREIGN KEY (`proyectId`) REFERENCES `proyect` (`proyectId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `piece` (
`proyectId` int(10) unsigned NOT NULL,
`pieceId` int(10) unsigned NOT NULL,
`colorId` int(10) unsigned DEFAULT NULL,
`name` varchar(30) DEFAULT NULL,
PRIMARY KEY (`proyectId`,`pieceId`),
KEY `proyectId` (`proyectId`,`colorId`),
CONSTRAINT `piece_ibfk_1` FOREIGN KEY (`proyectId`) REFERENCES `proyect` (`proyectId`),
CONSTRAINT `piece_ibfk_2` FOREIGN KEY (`proyectId`, `colorId`) REFERENCES `color` (`proyectId`, `colorId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

So there are proyects that can have pieces. There are color catalogues for each proyect, and the pieces of each proyect may or may not have a color.
Please note the foreign keys that are in the color and piece table, especially in the piece table, because is a composite one, that ensures that pieces of a certain proyect can have only colors that belong to that proyect's catalog.

The point is, i did everything to get to the point: session.save(piece) and attributes are updated well.. but when i change the id of the color to another or just set the id to null is not working. No error, just not working.

So, does Hibernate is prepared to handle this situation?

Thanks in advance!
 
Are we home yet? Wait, did we forget the tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic