Reputation: 5552
Is there any way to create bogus Predicate in JPA? Sort of like this:
CriteriaBuilder cb = em.getCriteriaBuilder;
Predicate pred = cb.isTrue(false);
Almost all the methods of CriteriaBuilder take Expression as parameter. I also tried this to no avail:
Expression<Object> path = cb.coalesce.value(null);
Predicate pred = cb.isNotNull(path);
Obviously it throws NPE, however I thought that this might work, because according to API documentation:
A coalesce expression is equivalent to a case expression that returns null if all its arguments evaluate to null, and the value of its first non-null argument otherwise.
Upvotes: 9
Views: 10748
Reputation: 926
dijunction
did not work for me in more complicated query in Eclipselink 2.4.
What did was cb.isTrue(cb.literal(false))
which is as precise representation of false as one can get.
Upvotes: 11
Reputation: 692151
I think a disjunction is what you're looking for. It's false by default, until some real predicate is or
ed to it.
Upvotes: 10