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]