You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Stephane Bailliez <sb...@imediation.com> on 2001/12/18 19:31:21 UTC

Criteria strikes again...

Complex query strikes again.

I can't find a correct way to express the following condition:

(a = a1 and b = b1 and c = c1) or ( a = a2 and b = b2)

cr1 = cri.getNewCriterion(a, a1, Criteria.EQUAL);
cr2 = cri.getNewCriterion(b, b1, Criteria.EQUAL);
cr3 = cri.getNewCriterion(c, c1, Criteria.EQUAL);

cr4 = cri.getNewCriterion(a, a2, Criteria.EQUAL);
cr5 = cri.getNewCriterion(b, b2, Criteria.EQUAL);

the following ( as advised in howto or many labels )
cri.add( cr1.and(cr2).and(cr3).or(cr4.and(cr5)) );

gives: cr1 or (cr4 and cr5) and (cr2 and cr3) which is quite expected
considering how the criteria manages the or and the and and due to the
criterion chaining.

invert cr5 and cr4 so that the and and the or does not refer to the same
column is of course even worse...
cri.add( cr1.and(cr2).and(cr3).or(cr5.and(cr4)) );

the only solution I have found so far is to perform a query for both
'cr1.and(cr2).and(cr3)' and 'cr4.and(cr5)' and merge the results... :-(

Stephane

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>