-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL "IN" operator usage?
PostPosted: Thu May 05, 2005 10:29 am 
Newbie

Joined: Thu May 05, 2005 10:19 am
Posts: 3
Not sure whether there are other posts in the forums on this topic ("in", not surprisingly, appears to be a stop-word in the forum search), but anyway, here's my issue: I've got HQL something like this:

from ...item
where item.visibility in ?

--where visibility is a String. I want the SQL to work out to:

...from item
where item.visibility in ('A', 'B', 'C')

But I can't find an example of what object type my parameter should be. When I found that passing a string such as "A, B, C" or "'A', 'B', 'C'" wouldn't work, it was suggested to me that I should be passing a String[] or a Collection implementation such as an ArrayList, but neither of those has worked either. Is it that I need parens around the questionmark? I didn't think HQL was quite so finicky, but I'm at a loss to find a single example of usage as above.

Can anybody help with an example? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 11:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
you need to put the parens in your HQL i.e., "...in (?)" and then bind the list of values you want Hibernate to expanded into the placeholder. Not sure whats so finicky about it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 05, 2005 11:45 am 
Newbie

Joined: Thu May 05, 2005 10:19 am
Posts: 3
Thanks for the help, but I'm still having trouble-- I've got parens around the bind parameter, and I've again tried passing several different values:

"A, B, C"

"'A', 'B', 'C'"

new String[] {"A", "B", "C"}

Collection visibility = new HashSet();
visibility.add("A");
visibility.add("B");
visibility.add("C");

But none of these are working for me...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 7:48 pm 
Newbie

Joined: Thu Jul 07, 2005 2:14 pm
Posts: 6
They HAVE to be in the form ('A', 'B', 'C')
The way I did this was just to say
"where name in (" + string + ")"

and just make the string you need to, but not pass it in as a parameter.
Hope that helps


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