Frage

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?

War es hilfreich?

Lösung

As documented, conjunction with zero conjuncts is true. Such a predicate can be created as follows:

CriteriaBuilder cb ...
Predicate conjunction = cb.conjunction();

When opposite is needed, that is task for disjunction (with zero disjuncts it is false):

CriteriaBuilder cb ...
Predicate disjunction = cb.disjunction();

Disjunction without disjunct typically generates something like 1=0 to SQL query.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top