My query is to get the number of days from the difference between two date fields and compare it to a specified value.
select
*
from
transaction transactio0_
where
transactio0_.order_status=?
and (
transactio0_.date_start between ? and ?
)
or DATE_PART(?,transactio0_.date_end-transactio0_.date_start)=100.0;
Since there will be a variable amount of conditions, I am unable to use native query, therefore specification is required.
I have provided the specification condition as below
spec = spec.and((root, query, builder) -> {
return builder.equal(
builder.function("DATE_PART", Double.class, builder.literal("day"),
builder.diff(endDate,startDate )),
filter.orderPendingDays());
});
The query was originally generated as follows.
DATE_PART('day',transactio0_.date_end-transactio0_.date_start)
I was using hibernate 5, then after switching to hibernate 6, the following things occurred.
This is how the query is generated after migration.
DATE_PART('day',extract(epoch from t1_0.date_end-t1_0.date_start)*1e9)
Currently, an error is being thrown.
Caused by: org.postgresql.util.PSQLException: ERROR: function date_part(unknown, double precision) does not exist
Could someone please explain the issue to me?