-->
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: need clarifications about retrieve by foreign_key
PostPosted: Fri Sep 12, 2003 10:38 am 
Newbie

Joined: Tue Sep 09, 2003 3:40 pm
Posts: 9
I got the following example from old disscussion forum about how to
retrieve by foreign key. I also check 9.7 of doc. But I am still not clear
about how this gonna work.

"FROM foo IN CLASS eg.Foo WHERE foo.bar.id = 666

(The second query is efficient. No table join is required.)"

Here foo and bar has on-to-many relationship, in order to retrieve a set of
bars based on its foreign key. Bu I don't understand what foo.bar.id means exactly. Is "bar" a set of bars defined in Foo class? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 10:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
bar is a <many-to-one>


the query should be written

FROM Foo foo WHERE foo.bar.id = 666

in Hibernate2


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 12:00 pm 
Newbie

Joined: Tue Sep 09, 2003 3:40 pm
Posts: 9
Thanks,

I am still not sure about this.
So, here, Foo has many Bars, Bar has a <many-to-one> association with
Foo, right? So, basically, the following query tries to retrieve a Foo using
one Bar's foreign key?

What I want to do is: retrieve a set of Bars based on a given Foo's PK. How
to do this?


gavin wrote:
bar is a <many-to-one>


the query should be written

FROM Foo foo WHERE foo.bar.id = 666

in Hibernate2


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 12:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
What I want to do is: retrieve a set of Bars based on a given Foo's PK. How
to do this?


If that is all you want then:


from Bar bar where bar.foo.id = ?


(assuming that this is a bidirectional association)


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.