-->
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.  [ 6 posts ] 
Author Message
 Post subject: HQL Query
PostPosted: Thu Feb 26, 2004 12:37 pm 
Newbie

Joined: Fri Feb 06, 2004 10:16 am
Posts: 7
Hi,

My problem is with this query (taken from the documentation):

"select elements(cat.kittens) from eg.Cat cat"

Now, what if I want to have some conditional restictions on the kittens collection that is to be returned...how could I write that?

Thanks in advance

/Klas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 12:47 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Wonder if something like this would work...

Code:
select kit from eg.Cat cat, eg.Cat kit where kit in elements(cat.kittens) and <your condition on the kit>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 6:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Or probably
Code:
select kit from eg.Cat cat join cat.kittens as kit where kit.something = 1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 7:01 pm 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
gloeglm wrote:
Or probably
Code:
select kit from eg.Cat cat join cat.kittens as kit where kit.something = 1


You are right - cleaner ;-)
Side question: are these two queries not supposed to do the same - what are the difference in how Hibernate will handle them ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 7:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I think they should produce the same results, but in elements will produce a subselect in the generated SQL, while the join will just produce a join :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 3:39 am 
Newbie

Joined: Fri Feb 06, 2004 10:16 am
Posts: 7
It worked very well. Thanks gloeglm.

/KBaze


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