-->
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.  [ 5 posts ] 
Author Message
 Post subject: Association with different foreign key column name
PostPosted: Wed Nov 05, 2003 4:51 pm 
Beginner
Beginner

Joined: Wed Nov 05, 2003 4:38 pm
Posts: 29
I have an existing database that has two tables Company and Claim.

Company
company_id
....


Claim
claim_id
tier_company_id - foreign key to Company
....


There are no examples in the docs that show any mappings that have different column names (it is assumed Claim would have company_id instead of tier_company_id). This causes confusion on when and where you should put company_id or tier_company_id in the mapping. This is compounded by the documentation for key, index, and element whcih are either short and cryptic or practically non-existent.

Could someone please provide me with an example mapping for the above two tables that has a many-to-one inverse relationship between the two?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 5:01 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Er.... Doesn't it work?

For Claim:
<many-to-one name="company"
column="tier_company_id"
class="Company"
/>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 5:03 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
If you need mapping from Company to Claim:

For Company:
<set name="claims"
table="CLAIM"
inverse="true"
lazy="true">

<key column="tier_company_id"/>
<one-to-many class="Claim"/>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 5:06 pm 
Beginner
Beginner

Joined: Wed Nov 05, 2003 4:38 pm
Posts: 29
That part of the association seemed to make the most sense to me (I guessed that that was how it should go). I'm having more trouble with the other part...

<set name="claims" inverse="true" lazy="true">
<key column="company_id"/>
<one-to-many class="Claim"/>
/set>


Should "key column" be company_id or tier_company_id?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 5:07 pm 
Beginner
Beginner

Joined: Wed Nov 05, 2003 4:38 pm
Posts: 29
Thanks that clears it up!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.