0

Working scenario:

Service-A : with Java 8 , Spring boot 2.7.x

  • Setting the ZoneddateTime ("America/New_York") in java object and adding it in RabbitMQ queue.

Service-B : with Java 8 , Spring boot 2.7.9

  • Receives the ZoneddateTime from Queue and persisting it in MySql DB.
  • ZoneddateTime is persisted in EST/EDT format as expected.

Mysql DB:

  • Result of the query (SELECT @@system_time_zone;) is EDT.
  • data type column in MySQL store the ZoneddateTime is - datetime

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 :

  1. I tried to convert the time to EDT/EST and then persist in DB. But still its storing it in UTC format only.
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

  1. I downgraded the spring boot version to 2.7.9 with Java 17. the ZoneddateTime is persisted in EST/EDT format as expected. So the issue is not due to the Java upgrade i guess.

Any recommendations or suggestion to fix this issue or to debug it further? I am expecting the datetime should be in EDT/EST format.

11
  • Who is the exact data type of your column in MySQL? Commented Sep 24, 2024 at 16:33
  • ZonedDateTime is not mapped in JDBC to any data type in SQL. (Nor Instant). A moment exchanged with a SQL database must be OffsetDateTime. Commented Sep 24, 2024 at 16:35
  • @BasilBourque data type in MySQL is - datetime Commented Sep 24, 2024 at 16:38
  • What type (fq package name please) is obj? Commented Sep 24, 2024 at 17:18
  • @g00se obj is from our entity classs. Data type of the request time is ZonedDateTime. imported these two packages import jakarta.persistence.*;import java.time.ZonedDateTime; in our class Commented Sep 24, 2024 at 17:27

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.