Improved mapping of ZonedDateTime and OffsetDateTime in Hibernate 6

preview_player
Показать описание
Working with timestamps with timezone information has always been a struggle. Since Java 8 introduced the Date and Time API, the classes OffsetDateTime and ZonedDateTime have become the most obvious and commonly used types to model a timestamp with timezone information. And you might expect that choosing one of them should be the only thing you need to do.
But unfortunately, that isn’t the case if you want to persist this information in a relational database. Even though the SQL standard defines the column type TIMESTAMP_WITH_TIMEZONE, only a few databases support it. Due to that, the JPA specification doesn’t support OffsetDateTime and ZonedDateTime as attribute types. Hibernate 5 supports them by normalizing the timestamp and storing it without timezone information. Hibernate 6 improves on this and provides a clear and flexible mapping for these types.

Like my channel? Subscribe!

Want to connect with me?
Рекомендации по теме
Комментарии
Автор

For the people who did upgrade to spring 3, you can revert old behaviour for time with this config; normalize

rfatcakr
Автор

You forgot to mention the Data Type of the Table column where you intend to store the ZonedDateTime Value :(

faisalsal
Автор

What a stupid mess with all this classes. How Jesus Crist i should write hibernate entities ? Should i use Date/Instant/OffsetDateTime for my datetime field or what ? Can't find normal answer, everybody write a lot of words but nobody can answer how to write simple program and not to have headache about all this timezones. Now we use plain Date class and i'm not sure when hibernate or jpa punch me in nose because of different timezone processing (when i compare date param and NOW() it goes weird, i understand why, but it too complex to maintain).

zigzag