Hello,
I'm using the Criteria API and i Need to produce such SQL
from Foo f where a=? and (b=? or b=? or b=? or b=?)
but i only managed to produce that
from Foo f where a=? and (((b=? or b=?) or b=?) or b=?)
Is it possible to limit the brackets ?
I'm also obliged to limit the size of my SQL so every 300 criterions, i create a new request.
Hibernate version: 2.1.7
Code between sessionFactory.openSession() and session.close():
Code:
List criteriaList = new ArrayList();
String a = "bar";
int i = 0;
for (Iterator iter = fooBCodes.iterator(); iter.hasNext(); i++) {
String b = (String) iter.next();
criterion = Expression.eq("b", b);
if (currentCriterion == null) {
crit = session.createCriteria(Foo.class);
crit.add(Expression.eq("a", a));
currentCriterion = criterion;
} else {
currentCriterion = Expression.or(currentCriterion, criterion);
}
if (i > 300) {
i = 0;
if (currentCriterion != null) {
crit.add(currentCriterion);
}
criteriaList.add(crit);
currentCriterion = null;
crit = null;
}
}
if (crit != null) {
if (currentCriterion != null) {
crit.add(currentCriterion);
}
criteriaList.add(crit);
}