spring-data-jpa
spring-data-jpa copied to clipboard
Invalid value for NanoOfSecond between 12am and 1am
DateTimeException is thrown when select operation with entity that contains java.time.LocalTime is performed between 12am and 1am (00:00-01:00)
error message:
Invalid value for NanoOfSecond (valid values 0 - 999999999): -329000000
java.time.DateTimeException: Invalid value for NanoOfSecond (valid values 0 - 999999999): -329000000
note that the value is random.
demo project is available HERE Steps to reproduce:
- Set time on your machine between 00:00-01:00
- Either run:
testunit testdocker-compose up -dand start the application
This sounds very much like a Hibernate issue, since all the JPA mapping and almost all of the conversions are done by it. I recommend creating a reproducer based purely on Hibernate and submitting an issue with them.
If you think this is actually a Spring Data issue, please provide a reproducer for the issue including a test case that demonstrates the correct behaviour using the EntityManager directly.
I am not able to provide correct behaviour using the EntityManager in spring boot project, however it works in hibernate-only project, without springboot. Project available HERE
I tested it with Hibernate 6.5.0.CR2 and springboot 3.3.0-RC1, that uses the same Hibernate version.
I ran into the exact same issue, by accident, right now. Currently trying to narrow it down, just want to second that we also have this issue with an application on spring 3.1.11 base. Since this issue does not have more traction it is fair to assume some additional factors are relevant, or simply no one uses LocalTime ;)
Looks like this bug here: https://hibernate.atlassian.net/jira/software/c/projects/HHH/issues/HHH-17229?filter=allissues&jql=project%20%3D%20%22HHH%22%20AND%20text%20~%20%22localtime%20nanosecond%22%20ORDER%20BY%20created%20DESC
At least for me it was the mentioned bug in hibernate. The fixed Hibernate-Version is included in Spring Boot 3.4.0. My pretty wild speculation is that LocalTime is rarely used in combination with the clock to store a value and most of the time with specific things like LocalTime.of(12, 0) or so, which will not trigger the bug.
Anyway, as a workaround for anyone running into this, truncate the LocalTime to seconds (LocalTime.now().truncatedTo(ChronoUnit.SECONDS)) and than it looks like you are fine.
At least all my tests which broke and triggered the bug before are now green.
Thanks for finding the Hibernate ticket.
I'm closing this one. If someone can show this is is a different problem an still exists, please let us know with a new ticket.