[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1123?page=c...
]
Duke Biswas commented on HHH-1123:
----------------------------------
Hi:
I am not sure if you guys alread feagured this out but I have solution and I am attaching
here
[code]
/**
* Special In Expression that handle maximum indentifiers. Note: This class
* could become an extension to Hibernate.
*
* @author BiswaD
*
*/
static class StockroomInExpression implements Criterion {
private static final long serialVersionUID = 1224146978925624808L;
protected static final int MAX_PARAMETER = 1000;
private String propertyName;
private Criterion criterion;
protected StockroomInExpression(String propertyName, String[] values) {
this.propertyName = propertyName;
this.criterion = buildSingleInCriterion(values, null, 0,
MAX_PARAMETER);
}
public TypedValue[] getTypedValues(Criteria criteria,
CriteriaQuery criteriaQuery) throws HibernateException {
return criterion.getTypedValues(criteria, criteriaQuery);
}
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
return criterion.toSqlString(criteria, criteriaQuery);
}
/**
* Recursive method that will create criterion that will have inner
* criterion with OR IN statement
*
* @param values
* @param lhs
* @param startIndex
* @param recordSize
* @return
*/
private Criterion buildSingleInCriterion(String[] values,
Criterion lhs, int startIndex, int recordSize) {
if (startIndex >= values.length) {
return lhs;
} else if (recordSize + startIndex > values.length) {
return buildSingleInCriterion(values, lhs, startIndex,
values.length - startIndex);
} else {
String[] tempArray = values;
// Create a Temp array only if the current requested record size
// is less then selected bottles total size
if (values.length > recordSize) {
tempArray = new String[recordSize];
System.arraycopy(values, startIndex, tempArray, 0,
tempArray.length);
}
Property prop = Property.forName(propertyName);
if (lhs == null) {
lhs = prop.in(tempArray);
} else {
lhs = Restrictions.or(lhs, prop.in(tempArray));
}
return buildSingleInCriterion(values, lhs, startIndex
+ recordSize, recordSize);
}
}
}
[/code]
Cannot put more than 1000 elements in a InExpression
----------------------------------------------------
Key: HHH-1123
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1123
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.1 rc2, 3.2.0.alpha1
Environment: Oracle 9i
Reporter: Alexis Seigneurin
Attachments: patch.txt
Original Estimate: 1 hour
Remaining Estimate: 1 hour
The number of elements that we can put in a "in" expression is limited to a
certain amount (1000 for Oracle, for instance). When creating a criteria query, the
org.hibernate.criterion.InExpression class should split the expression into several
smaller ones.
Attached is a patch which splits the expression by slices of 500 elements. For example,
if we have 1001 elements to put in the "in" expression, the result would be :
(entity.field in (?, ?, ?...) or entity.field in (?, ?, ?...) or entity.field in (?))
The surrounding parantheses are useful to avoid problems with other conditions (a
"and" condition taking over the one of the "or" conditions).
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira