I'm forming a query where I'm comparing the db result with API request data, but i'm getting below error:
Cannot resolve method 'greaterThan(int, int)'.
My code looks something like below. 2 is coming from the API request.
List<Predicate> predicates = new ArrayList<>();
predicates.add(criteriaBuilder.greaterThan(myFunc(root.get("amt")),2));
Basically myFunc function would multiply root.get("amt") with some number based on some condition. but this is not working for me as both expressions are of type "int" and it does not expect that. How to form specification in this kind of scenario.
The signature for
greaterThanis:In other words, it takes arguments that are
Expressionobjects whose value type (Y) implementsComparable<? extends Y>. Java doesn't know how to convert two integers into twoExpressionobjects. (In fact, I can't think of any PL that would be able to do that conversion without you saying what kind ofExpressionyou need there.)However, if you look at the javadoc for
CriteriaBuilderyou will also see somegtmethods that createPredicateobjects to compareNumberinstances. So the following ought to work:CORRECTION
because the first argument of
gtneeds to be an expression too.