views:

1723

answers:

3

Hi,

small questions about Restrictions.or and Restrictions.and

If I do something like this:

...
criterion = criterionA;
criterion = Restrictions.and(criterion, criterionB);
criterion = Restrictions.or(criterion, criterionC);
criterion = Restrictions.and(criterion, criterionD);

Will this be treated as:

(A and B) or (C and D) (following mathematical conventions)

Or will it be treated in the order it the restrictions have been added:

(((A and B) or C) and D)

Please also add references if there are any...

+1  A: 

It should be treated as the latter

(((A and B) or C) and D)

You could do

criterion = Restriction.or(Restrictions.and(criterionA, criterionB), Restrictions.and(criterionC, criterionD))

If you want the first solution

jitter
+1  A: 

there are no precedence rules (like in a programming language or in a CFG parser), method calls order unambiguously determines the expression.

(A and B) or (C and D) must be translated to:

import static org.hibernate.criterion.Restrictions.*;
...
criterion = or(and(A, B), and(C,D));
dfa
A: 

On a similar note, is it possible to do:

A or (B and C) or (D and E) or (F and G)?