I have these two tables:
CREATE TABLE IF NOT EXISTS `functions` (
`idFunction` int(11) NOT NULL,
`idLanguage` int(11) NOT NULL,
`name` varchar(30) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`idCategory` int(11) DEFAULT '1',
PRIMARY KEY (`idFunction`,`idLanguage`),
KEY `idCategory` (`idCategory`),
KEY `idLanguage` (`idLanguage`),
CONSTRAINT `FK_functions_categories` FOREIGN KEY (`idCategory`) REFERENCES
`category_package` (`idCategory`) ON DELETE NO ACTION ON UPDATE CASCADE,
CONSTRAINT `FK_functions_languages` FOREIGN KEY (`idLanguage`) REFERENCES `languages` (`idLanguage`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `subfunctions` (
`idParent` int(11) NOT NULL,
`idChild` int(11) NOT NULL,
PRIMARY KEY (`idParent`,`idChild`),
KEY `idChild` (`idChild`),
CONSTRAINT `FK_subfunctions_functions` FOREIGN KEY (`idParent`) REFERENCES `functions` (`idFunction`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_subfunctions_functions_2` FOREIGN KEY (`idChild`) REFERENCES `functions` (`idFunction`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
And when I'm trying to map these tables through Hibernate's Reverse Engineering the mapping occurs but when I try to do a query involving the two tables Hibernate throws me this exception:
Foreign key (FKFD0F515B161D5928:subfunctions [idParent])) must have same number of columns as the referenced primary key (functions [idFunction,idLanguage])
I know that the real deal is to put idLanguage as a PK in subfunctions table too, but I'm using a legacy DB and I can't modify it.
Is there any way to map this?