We implemented a solution for this problem by implementing the Criterion interface separately:
Code:
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
// String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName);
// String singleValueParam = StringHelper.repeat( "?, ", columns.length-1 ) + "?";
// if ( columns.length>1 ) singleValueParam = '(' + singleValueParam + ')';
// String params = values.length>0 ?
// StringHelper.repeat( singleValueParam + ", ", values.length-1 ) + singleValueParam :
// "";
// String cols = StringHelper.join(", ", columns);
// if ( columns.length>1 ) cols = '(' + cols + ')';
// return cols + " in (" + params + ')';
String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName);
String singleValueParam = StringHelper.repeat( "?, ", columns.length-1 ) + "?";
if ( columns.length>1 ) singleValueParam = '(' + singleValueParam + ')';
/**
* If the values are greater than 1000,
* write separate in expressions with
* or conditions.
*/
final StringBuffer totalIn = new StringBuffer();
int iStart = 0;
if (values.length > 999) {
while (iStart != values.length) {
String cols = StringHelper.join(", ", columns);
if ( columns.length>1 ) cols = '(' + cols + ')';
String params = StringHelper.repeat( singleValueParam + ", ", Math.min(1000, values.length - iStart) - 1 )
+ singleValueParam;
totalIn.append(cols + " in (" + params + ')');
iStart += Math.min(1000, values.length - iStart);
if (iStart != values.length) {
totalIn.append(" or ");
}
}
return "("+totalIn.toString()+")";
}
String params = values.length>0 ?
StringHelper.repeat( singleValueParam + ", ", values.length-1 ) + singleValueParam :
"";
String cols = StringHelper.join(", ", columns);
if ( columns.length>1 ) cols = '(' + cols + ')';
return cols + " in (" + params + ')';
}
It would be good if we could incorporate something like this in the Restrictions class in the in() method itself. I will also post it in JIRA.