문제

While writing following statement, Eclipse suggested me to cast criteriaBuilder.equal method call to (CriteriaBuilder) so that I can call "and" method of CriteriaBuilder.

criteriaQuery.where((criteriaBuilder.equal(subscriptionRoot.get("user"), user))
                .and(criteriaBuilder.equal(subscriptionRoot.get("plan"), plan)));

Note that "equal" method returns an object of type Predicate. I was looking into Java API of CriteriaBuilder interface and Predicate interface. I could not find CriteriaBuilder and Predicate in the same tree.

I think this is a basic Java question. How is it possible to cast object that implements Predicate to an Object that implements CriteriaBuilder?

Thanks.

도움이 되었습니까?

해결책

Instead of that, you need this code:

criteriaQuery.where(criteriaBuilder.and(
    criteriaBuilder.equal(subscriptionRoot.get("user"), user),
    criteriaBuilder.equal(subscriptionRoot.get("plan"), plan)));

CriteriaQuery.and takes several parameters, each Predicates that should be anded together.

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