-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to map list with primary/foreign key col names different
PostPosted: Tue Dec 16, 2003 7:39 pm 
Newbie

Joined: Tue Dec 16, 2003 7:06 pm
Posts: 3
Hello,

I have a text_value table with "chunked" text in a legacy database. The text table resembles the following:

txt_id (collection identifier)
txt_ord (ordinal index)
txt_value (string field)

In another table (tableA) that populates a class (classA) I have a field that references the string value in the text table:

my_txt_id (foreign key to text_value table)
table_a_id (primary key)

I'd like to populate a List of Strings in classA from the text_value table using my_txt_id as a foreign key.

I did not see anywhere in the documentation how to specify distinct column names for the primary key in the collection table and the foreign key in the "owning" table. I did discover the apparently undocumented foreign-key attribute of the key element, and tried the following:

<list name="myTextChunks" table="text_value">
<key column="txt_id" foreign-key="my_txt_id" />
<index column="txt_ord" />
<element column="txt_value" type="java.lang.String" />
</list>

However, this did not do what I had hoped. Instead of joining the text_value.txt_id to tableA.my_txt_id, it is joining text_value.txt_id to tableA.table_a_id (the id of the owning class).

Should this have worked?

Is there a better way to do this?

Thanks,
John


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 9:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Please refer to the Hibernate documentation and examples.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 11:47 am 
Newbie

Joined: Tue Dec 16, 2003 7:06 pm
Posts: 3
Could you please point me at where in the documentation it discusses how to create a relationship between an owning table and a collection table where the collection table's primary key is not joined to the primary key of the "owning" table? I have read through the relevent chapters of the documentation several times and have not found the answer, maybe I'm not looking in the right place.

I did find documentation on top-level collections at http://www.xylax.net/hibernate/toplevel.html, and this would seem to provide the mapping I want. Alas, it appears that this feature has been removed from hibernate 2.0.

John


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 11:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
collection table's primary key is not joined to the primary key of the "owning" table


Oh, this is not supported. In a properly designed relational model, all foreign keys reference primary keys, of course. We do support this for <many-to-one>, but we probably shouldn't.

P.S. Please be clearer next time. TIA.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.