-->
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.  [ 1 post ] 
Author Message
 Post subject: simple join
PostPosted: Tue Jan 09, 2007 1:26 pm 
Newbie

Joined: Wed Sep 06, 2006 10:35 am
Posts: 14
I have 3 classes (A,B,C) each of which is mapped to a table using nhibernate mapping files. I want to have a situation where:

A has a 1-M association to B
B has a 1-M association to C

and the HBM files have the ID field and one property that represents the foreign key (B.hbm.xml has one called FOREIGH_KEY_A and C.hbl.xml has one called FOREIGH_KEY_B)

I want to get all the rows in C that are related to A through these associations.

I know I can define "<one-to-many... " associations in the mapping files and then do: (pseudo code)
Code:
Iset intermediateResults = A.Bset();
for each B in intermediateResults
   finalResults.append(B.Cset());


to get the results. However, this means fetching every B object associated with A, where I really just want to retrieve those objects that are associated to Cs. (let's sat there is 1 A, a million Bs and only 1 of those has an associated list of Cs... I want to retrieve just 1 B not a million)

Given that all these classes are correctly mapped to their own tables, I can take out the "<one-to-many..." statements and just add my own mapped properties to B and C call FOREIGH_KEY_A and FOREIGH_KEY_B respectively. Then, an alternative way of doing this would be to use something like this HQL statement.

Code:
FROM MyNamespace.A a, MyNamespace.B b, MyNamespace.C c
WHERE b.FOREIGH_KEY_A = a.ID
    AND c.FOREIGH_KEY_B = b.ID



this seems to be the right solution for me. the trouble is, I get the following exception from hibernate:

undefined alias or unknown mapping: MyNamespace [FROM MyNamespace.A a, MyNamespace.B b, MyNamespace.C c
WHERE b.FOREIGH_KEY_A = a.ID
AND c.FOREIGH_KEY_B = b.ID]



Any ideas????? do i need to have the "<one-to-many" statements in the mapping even though I am using straight HQL? or is the problem something more fundamental?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.