• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Hibernate and Composite Foreign Keys

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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!
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic