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.  [ 5 posts ] 
Author Message
 Post subject: question about mulitple joins in a HQL or Criteria query
PostPosted: Fri Aug 26, 2005 11:31 pm 
Newbie

Joined: Fri Aug 26, 2005 11:22 pm
Posts: 3
i've combed through the documentation, but i'm having a problem that i'm still unclear about.

i have a few mapped objects:

Code:
public class A {
  List<B> AToBLinks;
}

public class B {
  A AObject;
  C CObject;
}

public class C {
  String name; 
}


as you can see, B links objects A and C together (there is a bunch more metadata in B that i'm not including for brevity).

what i've been trying to do is to issue a query along the lines of (this is in "psuedo-query", and not in HQL or SQL)

'find all the As where A.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 11:35 pm 
Newbie

Joined: Fri Aug 26, 2005 11:22 pm
Posts: 3
(sorry - i entered the message before finishing it)

i would like to issue a query along the lines of

'find all the As where A.AToBLinks.C.name = "foo" and A.AToBLinks.C.Name = "bar"'

as there can be many C objects hung off the A objects (through a B link), i'm looking for all the A objects which have (implicitly) more than one C object associated to it, and where one of the objects has a name property of "foo" while another one of the objects has a name property of "bar".

can somebody please point me how to create a HQL query that will do that? also, if you can show me how to build a Criteria object that also does it (if that is even possible), i will be really appreciative.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 11:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
select distinct b.A from B as b where b.C.name = 'foo' or b.C.name = 'bar'


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 27, 2005 12:36 am 
Newbie

Joined: Fri Aug 26, 2005 11:22 pm
Posts: 3
thank you so much - that's brilliant, it didn't occur to me to select on the link instead. is it possible to translate that type of query to Criteria objects (i'm not sure i entirely understand how as the select is being done on a different object than one being returned), or should i have my application simply (but carefully) build the HQL query instead?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 28, 2005 1:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
There should not be any issue geting the critera API to work with this. Having said that I just don't use it all that much so I am a bit rusty. HQL feels quite natural to me. Anycase, with H3.x improvements its a much more attractive API and I can see myself exploring it further.


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