-->
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: Help!
PostPosted: Tue Aug 09, 2011 3:38 pm 
Newbie

Joined: Tue Aug 09, 2011 3:25 pm
Posts: 1
For whatever reason, there exists 2 tables LOC (Location - Key Location_Key:LONG) and LOC_ATTR (Location Attributes - Key Location_Attr_Key:LONG) with a one-to-one association, in the sense that one row in LOC table has one and only one row in LOC_ATTR table [sigh!]. Add to that, the only way to index into LOC_ATTR is through Loc_Code:STRING (1 Location_Key = 1 Loc_Code in LOC table). Why Location_key wasn't used in LOC_ATTR is beyond my understanding .. and I cannot change the table structures!

LOC table:
Code:
Location_Key : LONG
Loc_Code : STRING
. . . more data . . .


LOC_ATTR table:
Code:
Location_Attr_Key : LONG
Loc_Code : STRING
. . . more data . . .


Question is this, how do I get LOC and LOC_ATTR using Hibernate? Please help!


Top
 Profile  
 
 Post subject: Re: Help!
PostPosted: Wed Aug 10, 2011 3:43 am 
Beginner
Beginner

Joined: Sat Nov 07, 2009 10:31 am
Posts: 22
This is called Primary key column join.

means Primary Key of Loc is refrred as Foriegn key in Loc_ATTR table and also Primary key.

LOC_CODE is primary key and also forign key in LOC_ATTR table.

This kind of mapping usually do in one-to-one association mapping.

How did you map this association? using hbm.xml or annotations?

once you map you can write a hibernate Query
"From LOC where loc_code=?" this will return LOC object

with this you can get LOC_ATTR by getLOC_ATTR(); because you LOC has LOC_ATTR.

try it out.

_________________
Jana


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