If you use LocalTime.now() and save something to a PostgreSQL database with that timestamp, the ORM will crash trying to read/save the value (particularly while converting java time to sql time). It’s something in LocalTimeJavaType.java at lines 123-139 of Hibernate ORM core version 6.2.5 Final. The error is as follows:
Exception in thread “main” java.time.DateTimeException: Invalid value for NanoOfSecond (valid values 0 - 999999999): -791000000
the values are random if writing, but are constant when reading.
also in that code “millis” are negative for some reason.
This does not happen if you use LocalTime.of() and provide the values yourself,
however it does happen if you use LocalTime.of(LocalTime.now().getHour(), LocalTime.now().getMinutes(), LocalTime.now().getSeconds()), even though the NanoOfSecond part is zero.
Steps to reproduce:
- Make sure it is between 12AM and 1AM.
- Create a persistent Entity with a LocalTime attribute defined by LocalTime.now()
- use the Session.persist function on it
- Try to commit the data
OR - use a query to fetch an entity which has a LocalTime attribute set by LocalTime.now() betweeen 12AM and 1AM