How to implement date diff to find out days between two dates using JPA criteria builder for Oracle?
Expression<Long> fromDate= root.get("fromDate");
Expression<Long> toDate= root.get("toDate");
builder.greaterThanOrEqualTo(builder.diff(toDate, fromDate), TimeUnit.DAYS.toMillis(days));
Query translator translates to below as expected but its throwing "SQLSyntaxErrorException: ORA-00932: inconsistent datatypes: expected NUMBER got DATE" error.
and nvl(cast(i0_.TO_DATE as number(19,0)), cast(current_date as number(19,0)))-i0_.FROM_DATE>=864000000
Oracle date difference is straight forward its just <to_date> - <from_date> which gives number of days. Not sure why we do not have diff option for dates using JPA/Hibernate criteria api or Criteria builder. Please let me know if there is any workaround.