Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is a timezone bug in OffsetDateTime in Spring Boot 3.1.0. #3035

Closed
ac-saro opened this issue Jun 21, 2023 · 5 comments
Closed

There is a timezone bug in OffsetDateTime in Spring Boot 3.1.0. #3035

ac-saro opened this issue Jun 21, 2023 · 5 comments
Labels
for: external-project For an external project and not something we can fix

Comments

@ac-saro
Copy link

ac-saro commented Jun 21, 2023

My working environment is as follows:
DB: 10.6.11-MariaDB
Timezone: +09:00 (system, db both)

You can reproduce the issue using the following steps:

@Entity
@Table(name = "forum_topic")
class Topic(
...
  @Column(nullable = false)
  var regDt: OffsetDateTime = OffsetDateTime.now(),
  
  @Column(nullable = false)
  var updDt: OffsetDateTime = OffsetDateTime.now(),
)

boardTopicRepository.save(Topic());

Starting from Spring boot 3.0.7 version, it is stored in the following format in the DB.
image
The data is stored in the DB as a properly formatted value with the applied timezone of +09:00.

However, starting from Spring Boot 3.1.0, it is stored as UTC-based value with a -9-hour offset.
When converted to OffsetDateTime in the DB, it does not apply the timezone, resulting in a output of -9 hours.
image

Both the server and the DB are configured with the +09:00 timezone.

@mp911de
Copy link
Member

mp911de commented Jun 22, 2023

Have you tried downgrading Hibernate to version 6.1?

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Jun 22, 2023
@ac-saro
Copy link
Author

ac-saro commented Jun 22, 2023

@mp911de

plugins {
    id("org.springframework.boot") version "3.1.0"
    ...
}
...
// spring boot 3.1.0 with hibernate-core:6.1.7
implementation("org.hibernate.orm:hibernate-core:6.1.7.Final")

I confirmed that it works fine after downgrading Hibernate to 6.1.7.

It seems to be a bug in Hibernate 6.2.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 22, 2023
@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Jun 26, 2023
@mp911de mp911de added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Jun 26, 2023
@bright-k
Copy link

https://docs.jboss.org/hibernate/orm/6.2/migration-guide/migration-guide.html#ddl-offset-time

The default setting for OffsetDateTime has been changed since Hibernate 6.2.x.
Have you tried using the setting in the mentioned document?

@ac-saro
Copy link
Author

ac-saro commented Jun 29, 2023

@bright-k
Thank you
It can be confusing that the default value has been changed, but it has been resolved with the NORMALIZE option.

If others need documentation, please refer to the following address:
https://thorben-janssen.com/hibernate-6-offsetdatetime-and-zoneddatetime/

@slankka
Copy link

slankka commented May 22, 2024

Using Hibernate 5.4.32 with MariaDb-10.0.38
mariadb-java-client 2.7.11

jdbcUrl :

jdbc:mariadb://a.b.c.d:3306/e?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&timezone=auto&useFractionalSeconds=true

JPA entity type Instant field with record.getCreateTime().getEpochSecond() returns wrong timestamp (db+8)

db: 2024-03-13T17:48:30 (1710323310)
DataGrip: 2024-03-13T17:48:30 (1710323310)
JPA: 2024-03-14T06:48:30 (1710370110)

@Column(name = "create_time", insertable = false, updatable = false)
private Instant createTime;

after setting this property, now epochSecond is correct

spring.jpa.properties.hibernate.jdbc.time_zone=GMT+8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

5 participants