-->
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 Using Lists as parameters
PostPosted: Tue Feb 17, 2004 4:43 pm 
Beginner
Beginner

Joined: Mon Jan 12, 2004 3:39 pm
Posts: 23
Hello everyone,

I need some help with HQL. I have and object X and it has a list of Ys and the Y object as an attribute Id. I pass to the where clause a list of Ids and I need a list of all my X's where any of its Y's has either one or more Ids I passed.


Just to illustrate the objects relationships:

Iterator i = X.getYs().iterator();

while(i.hasNext())
{
Y y = i.next();
Integer id = y.getId();
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 7:28 pm 
Newbie

Joined: Wed Feb 11, 2004 4:48 pm
Posts: 4
from the docs (8.3.2. The Query interface):

Query q = session.createQuery("select x from X x join x.ys y where y.id in (:ids)");

q.setParameterList("ids", someCollection);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 10:33 am 
Beginner
Beginner

Joined: Mon Jan 12, 2004 3:39 pm
Posts: 23
Ok, thanks for the help.

Just out of curiosity. Here is what I had done


from x as o , o.ys as list where list.id in (ids)


would it work?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 11:03 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
from x as o join o.ys as list where list.id in (:ids)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 12:50 pm 
Beginner
Beginner

Joined: Mon Jan 12, 2004 3:39 pm
Posts: 23
ok. now I have


from x as o join o.ys as list where list.id in (:ids)

What if X has an attribute date and I only want ro return de min(date)?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 1:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
What do you think of reading the reference guide.
The chapter 8.3 for example.

_________________
Emmanuel


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.