-->
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: PROBLEM: HQL query with IN clause
PostPosted: Mon Apr 05, 2004 11:13 pm 
Beginner
Beginner

Joined: Mon Feb 09, 2004 3:15 pm
Posts: 34
Hi everyone - I have a fairly simple query with an 'IN' clause:

Code:
SELECT myObject.id, myObject.fk
FROM MyObject as myObject
WHERE myObject.zipCode in (:zipCodeList)


I have tried binding the following to :zipCodeList in my code, all of which returned no results and threw no errors:

1.) a comma delimited list of zipCodes
2.) a comma delimited list of single-quoted zip codes
3.) a List object containing String objects (the zip codes)


Any ideas how to get an HQL query with an IN clause to return some results?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 05, 2004 11:26 pm 
Beginner
Beginner

Joined: Mon Feb 09, 2004 3:15 pm
Posts: 34
I'm an idiot....or the documentation could use a little work....

http://forum.hibernate.org/viewtopic.php?t=929302


Top
 Profile  
 
 Post subject: Here's how I did it
PostPosted: Tue Jul 25, 2006 9:01 am 
Newbie

Joined: Sun Apr 25, 2004 11:09 am
Posts: 2
I'm sure your question is answered by now, but this might help someone else.

If myObject.getZipCode() returns an object, the way you do an 'in clause' is like so:

Code:
SELECT myObject.id, myObject.fk
FROM MyObject as myObject
WHERE myObject.zipCode.id in (:zipCodeList)


where getZipCode().getId() returns the ZipCode's Hibernate id. Then you bind a List of ZipCode ids to :zipCodeList.

Hope that helps,
Bobby Martin
Legerity Group
Frimp.net


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.