-->
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.  [ 2 posts ] 
Author Message
 Post subject: WHERE IN (1, 2, 3) and JDBC "in" parameters
PostPosted: Sun Jan 16, 2005 2:03 am 
Newbie

Joined: Fri Jan 14, 2005 8:30 pm
Posts: 11
Description

I've got a situation where I've got a n number of parameter values that I need to use as the WHERE conditions in a query. I currently hold these values in an array.

I can loop over that array and generate the WHERE clauses by-hand. That much works great. Something like this (pseudo-code):

Code:
String sql = "from Table where "
for (int i=0; i++; i<StringArray.length() ) {
  String value = (String) StringArray[i];

  sql += "field = '" + value + "' AND ";
}


Ok, so obviously that code won't work exactly, it'll leave you with a dangling "AND" boolean, the for syntax is probably wrong, yadda, yadda. But hopefully it gets the idea across. That way will work.

But...

I noticed the WHERE IN syntax allows you to compare against an array of values. Hmmmm.

So is it possible to pass an array as a JDBC "in" parameter to a HQL query? In other words, it'd be nifty if I could do this:

Code:
List result = session.find("from Table where field in ?", StringArray, Hibernate.????);


There's no Hibernate "array" type (thus the Hibernate.????) so I'm thinking this isn't directly supported. But is there a workaround? The IN clause is very handy, I'd love to be able to bind an array to a query parameter when using it.

Thanks!

- Gary

Hibernate version:

2.1[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 16, 2005 4:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Query.setParameterList(String, Object[])

_________________
Max
Don't forget to rate


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