-->
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.  [ 3 posts ] 
Author Message
 Post subject: filtering with a list of ids
PostPosted: Thu Jan 03, 2008 6:48 pm 
Newbie

Joined: Wed Dec 05, 2007 1:30 pm
Posts: 5
Is something like the following possible with HQL:

String query = "from <somentity> a join... .... where a.id in :theList"

And then pass in a collection/array of ids as the 'theList' parameter

Though this seems like a common thing to want to do, the only work-around is some sort of ugly string hack, eg:

Code:
String s = "(";
for(Long id : theList){
  s += id + ", ";
}

//truncate the last comma, then add the closing parenthesis to the string...


Thanks
Bill


Top
 Profile  
 
 Post subject: solution
PostPosted: Fri Jan 04, 2008 2:04 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Don't know about HQL, but one of the Restrictions that you can add to a Criteria query is "Restrictions.in( collection )"

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 22, 2008 5:56 pm 
Newbie

Joined: Wed Dec 05, 2007 1:30 pm
Posts: 5
thanks so much - that was exactly what I was looking for!


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