Hi! I’m trying to use LocalDate.MAX with Hibernate and PostgreSQL. The PostgreSQL driver automatically converts it to ‘infinity’.
After enabling the java_time_use_direct_jdbc option, everything seemed to work as expected.
But I ran into a problem with native queries:
LocalDate gets converted to java.sql.Date, which causes this error:
org.postgresql.util.PSQLException: ERROR: date out of range: “169104628-12-09 BC +07”
This happens because PostgreSQL doesn’t support such a large date value.
At the same time, HQL queries work perfectly since LocalDate is passed directly to the driver.
I tried Spring Data native queries and EntityManager directly, but the issue is the same.
Is there any option to avoid this problem ?
Hibernate 6.6.2.Final
Query nativeQuery = entityManager.createNativeQuery("""
SELECT t.*
FROM my_entity t
WHERE t.date_field = :date
""", MyEntity.class);
Query date = nativeQuery.setParameter("date", LocalDate.MAX);
List resultList = date.getResultList();