Search code examples
querydsl

How to create ((E1 AND E2) OR (E3 AND E4)) AND E5 expression in QueryDSL


How to create below expression in QueryDSL

((E1 AND E2) OR (E3 AND E4)) AND E5

Solution

  • Simply: e1.and(e2).or(e3.and(e4)).and(e5). It will serialize as E1 AND E2 OR (E3 AND E4) AND E5 but that is not a problem as AND and OR share the same precedence and are evaluated left to right (in JPQL, see for example https://openjpa.apache.org/builds/1.2.3/apache-openjpa/docs/jpa_langref.html#jpa_langref_operators).