I'm using Spring Data JPA with a specification to select rows out of table if the user has selected certain filters:
public interface Specification { Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder cb); }
How do I create a predicate which will return everything?
As documented, conjunction with zero conjuncts is true. Such a predicate can be created as follows:
When opposite is needed, that is task for disjunction (with zero disjuncts it is false):
Disjunction without disjunct typically generates something like 1=0 to SQL query.