有关Restrictions.or和Restrictions.and
的小问题如果我这样做:
...
criterion = criterionA;
criterion = Restrictions.and(criterion, criterionB);
criterion = Restrictions.or(criterion, criterionC);
criterion = Restrictions.and(criterion, criterionD);
这会被视为:
(A and B) or (C and D) (following mathematical conventions)
或者它将按照添加限制的顺序进行处理:
(((A and B) or C) and D)
如果有任何......
,还请添加参考答案 0 :(得分:6)
应将其视为后者
(((A and B) or C) and D)
你可以做到
criterion = Restriction.or(Restrictions.and(criterionA, criterionB), Restrictions.and(criterionC, criterionD))
如果你想要第一个解决方案
答案 1 :(得分:2)
没有优先规则(如在编程语言或CFG解析器中),方法调用顺序明确地确定表达式。
(A和B)或(C和D)必须翻译为:
import static org.hibernate.criterion.Restrictions.*;
...
criterion = or(and(A, B), and(C,D));