-->
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: child relationship on FK; can't figure the hib option to use
PostPosted: Thu Jan 15, 2004 2:57 pm 
Newbie

Joined: Thu Jan 15, 2004 12:31 pm
Posts: 4
Using Hibernate 2.1, can't figure out solution to parent-child type scenarion:

foo
FOO_ID PK

bar
BAR_ID PK
FOO_ID
SEQUENCE
NAME

bar_data
FOO_ID
DATA

There is no PK on bar_data (i know, i know). I'm trying to retrieve all bars, where each bar also contains a Set of bar_data objects based on the FOO_ID FK.

Taking the bar_data out of the equation, i'm able to successfully retrieve all bars with this XML:

<class
name="bar"
table="bar"
mutable="false"
>

<id name="bar_id" column="BAR_ID" type="string">
<generator class="assigned"/>
</id>

<property name="name" column="name_ID" type="string"/>

</class>

I'm tried numerous things to no avail. the last thing i've tried was adding this with above:

<set name="bar_data" lazy="false">
<key column="FOO_ID"/>
<one-to-many class="bar"/>
</set>

But the SQL that is generated is filling in the bar_id in the FK select. 123 is the value of the BAR_ID value from the bar table:

select foo_id, data
from bar_data
where foo_id = 123

What I want is:

select foo_id, data
from bar_data
where foo_id = 456

Where 456 is the FOO_ID value from the bar table.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 5:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you really need a object mapped to the bar_data table you can use composite-element probably. If you dont, map it as a collection of value types, look at http://www.hibernate.org/hib_docs/reference/html/collections.html#collections-s1-5


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.