Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top