Working scenario:
Service-A : with Java 8 , Spring boot 2.7.x
Service-B : with Java 8 , Spring boot 2.7.9
Mysql DB:
Issue:
After upgrading the Service-B (service which persist the date time in DB) to Java 17 & Spring boot 3.2.9. ZoneddateTime is getting persisted UTC format (EDT + 4 hrs)
Debugging :
final ZonedDateTime inboundTimeEST = inboundTime.withZoneSameInstant("America/New_York"); obj.setRequestTime(inboundTimeEST); obj.setMyJson(XXX().getBytes()); // Json in bytes logsRepository.save(obj);
obj is from our entity class. Data type of the request time is ZonedDateTime. imported these two packages import jakarta.persistence.*;import java.time.ZonedDateTime; in our class
Any recommendations or suggestion to fix this issue or to debug it further? I am expecting the datetime should be in EDT/EST format.
This issue is due to the change in Hibernate 6.x behavior.
Spring Boot 2.x uses Hibernate 5.x , but the Spring Boot 3.x uses Hibernate 6.x.
In Hibernate 5, time zones were not stored, but normalized to the time zone set in hibernate.jdbc.time_zone / JVM time zone by default. But in Hibernate 6.x, date/time values are normalized to UTC.
More details are available in the Hibernate Migration guide
So, Setting the configuration property hibernate.timezone.default_storage to NORMALIZE reverts to the Hibernate 5’s behavior.