Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top