'How to create predicate that compares value in integer-column to difference in years in date-values of two other date columns?
Java, JPA, CriteriaQuery: I need to create predicate that implements the following for where clause: in plain SQL => c.limit_max >= DATEDIFF(YEAR,p.date_of_birth, c.limitValidateDate)
In Java code :
c.limit_max is join1.get(C_.Limit).get("max") - which does Not produce error during build or running code.
join1 is of type "From<Table1, C> join"
p.date_of_birth is root.get(P_.date_of_birth)
c.limitValidateDate is join1.get(C_.LimitValidateDate) of type SingularAttribute<C, LocalDate>
My most latest attempt to create predicate is:
Predicate PRDates3 = builder.greaterThanOrEqualTo( join1.get(C_.Limit).get("max"), ChronoUnit.YEARS.between(join1.get(C_.LimitValidateDate), root.get(P_.date_of_birth));
predicateList.add(PRDates3);
which does not accept lines in bold above:
Required type: Temporal
Provided:Path <java.time.LocalDate>
no instance(s) of type variable(s) Y exist so that Path conforms to Temporal
I am relatively new to java. I am googling for second day by now and have tried maaany different approaches. None worked so far. In SQL it is so simple. How to create predicate that compares value in integer-column to difference in years in date-values of two date columns ? (java, JPA, criteriaQuery, critireaBuilder) Please help. Many thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
