I am passing java.sql.Date object to CrudRepository native query. This date object is passed to a date function with a format ('YYYY-DD-MM'). This query is working with PostgreSQL 9.4, but it gives error when the database is PostgreSQL 11. I tried JDBC driver v42.2.11 and 9.1-901-1. Both are giving same result.
The error message is:
ERROR: date/time field value out of range: "2020-05-27 +00:00"
Code:
@Query(value = "SELECT TO_DATE(?1, 'YYYY-DD-MM')", nativeQuery = true)
public String sampleQuery(java.sql.Date date);
When I gave the date format as "SELECT TO_DATE(?1, 'YYYY-MM-DD')", that time it worked in PostgreSQL 11.
Any idea what is happening here.
to_date()on a value that is already adatemakes no sense whatsoever. So if you pass ajava.sql.Dateinstance to the query, then your query makes no sense. Did you mean to useto_char()in order to format the data?java.sql.Dateclass was supplanted years ago by the modern java.time classes defined in JSR 310, speciallyLocalDate. Both JPA 2.2 and recent Hibernate have been updated to support java.time types.