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.  [ 2 posts ] 
Author Message
 Post subject: many to one relationship with two different key names in tbl
PostPosted: Thu Aug 24, 2006 10:20 am 
Newbie

Joined: Fri Aug 18, 2006 6:47 am
Posts: 11
Two tables


Table Job
Table Employee


Employee(table)
CurrentJobId


Job( table )
JobId



Employee.hbm.xml
<many-to-one name="job" column="JobId" class="com.db.dataobject.Job"/>

Job.hbm.xml
<set name="employees" cascade="all" inverse="true" lazy="true">
<key column="CurrentJobId"/>
<one-to-many class="com.db.dataobject.Employee"/>

</set>



see the above example where the two columns are related i.e. the
currentJobId is the same as the JobId, and there are many employees to
one JobId. how do i represent that in the above two mapping files as
the names of the coulmns are different in each table?!?!


Top
 Profile  
 
 Post subject: Employee mapping
PostPosted: Thu Aug 24, 2006 1:00 pm 
Newbie

Joined: Thu Aug 24, 2006 11:58 am
Posts: 5
In the employee mapping for the job property, the column should refer to the CurrentJobId, not the JobId. Hibernate knows the class, so it will match the CurrentJobId to the JobId.

Employee.hbm.xml
Code:
<many-to-one name="job" column="[b]CurrentJobId [/b]" class="com.db.dataobject.Job"/>


The Job mapping looks ok AFAIK.


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.