문제

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:

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top