-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: creating foreign key constraint by many-to-one
PostPosted: Tue Jun 01, 2010 6:55 am 
Newbie

Joined: Sun Apr 11, 2010 6:44 am
Posts: 12
Hi

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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.