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.
I think a disjunction is what you're looking for. It's false by default, until some real predicate is or
ed to it.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With