Hi
It is a hibernate question.
I am trying to associate 2 tables by foreign key constraint. These 2 tables are job and jobtype.
There are only 2 jobtype. So the oid of the jobtype table will be used as the foreign key in job table, and the jobtype table should not be inserted any new row.
jobtype
0 lookingforjob
1 offerigjob
job
oid|description|jobtype
The mapping for jobtype in job.hbm.xml is the following
<many-to-one class=”Jobtype” name=”jobtype” cascade=”all”/>
As a result, the hibernate create the job table, but without the foreign key constraint reference. And eveytime a job is inserted to the job table, a new jobtype is also inserted to the jobtype table.
CREATE TABLE `job` (
`oid` BIGINT(20) NOT NULL AUTO_INCREMENT,
`description` VARCHAR(255) DEFAULT NULL,
`jobtype` BIGINT(20) DEFAULT NULL,
PRIMARY KEY (`oid`),
KEY `FK11F9D5D27BCB9` (`jobtype`)
) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1
How can I config the hibernate to create the job table with foreign key constraint references the oid of another table?
Thanks a lot