Restrictions on sleep mode and / or order

small questions about restrictions and limitations and limitations.

If I do something like this:

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

Will it be considered as:

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

Or it will be processed in the order in which the restrictions were added:

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

Please add links if available ...

+4
source share
2 answers

It should be considered as the last

 (((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

+5
source

there are no priority rules (for example, in a programming language or CFG parser), the order of method calls uniquely determines the expression.

(A and B) or (C and D) should be translated into:

 import static org.hibernate.criterion.Restrictions.*; ... criterion = or(and(A, B), and(C,D)); 
+2
source

Source: https://habr.com/ru/post/1286802/


All Articles