JPA Criteria API: how to express literal true and literal false?

Abdull picture Abdull · Feb 3, 2013 · Viewed 18.9k times · Source

How can I express literal true and literal false in JPA's Criteria API?

I'm looking for something like Predicate alwaysTrue = CriterialBuilder.DefaultLiterals.TRUE (analogous to java.lang.Boolean.TRUE).

Answer

JB Nizet picture JB Nizet · Feb 3, 2013

To get an always true Predicate instance, use criteriaBuilder.and().
To get an always false Predicate instance, use criteriaBuilder.or().