Hibernate ZonedDateTime persistence and zone data loss
0 reputation · 24 Feb 2022, 14:00 UTC
Regional Time Zone Handling in Java Persistence
When using java.time.ZonedDateTime for regional time tracking, there is a technical conflict between the Java object's ability to store a specific ZoneId and the default mapping behavior of Hibernate.
Standard Hibernate configurations often map ZonedDateTime to TIMESTAMP WITHOUT TIME ZONE. This behavior risks discarding the original zone offset, effectively converting the value to the server's local time or UTC without preserving the regional context necessary for accurate date conversion across different time zones.
To ensure data integrity during DST transitions and cross-regional queries, a decision is required regarding the storage strategy.
- Should timestamps be normalized to UTC at the persistence layer, requiring explicit conversion for user-facing displays?
- Is it more reliable to preserve the local zone in a separate column to avoid JDBC driver-induced double conversions?