Thorben Janssen
banner
thjanssen123.bsky.social
Thorben Janssen
@thjanssen123.bsky.social
I'm a freelance consultant and trainer helping Java developers create better persistence layers using Hibernate and Spring Data.
Co-organizer JUG Paderborn

https://thorben-janssen.com
https://thorben-janssen.com/join-persistence-hub/
You can watch Greg's entire session in the Persistence Hub:
thorben-janssen.com/join-persist...
Persistence Hub
The Persistence Hub is the quickest way to get your Java persistence skills to the next level! Get access to courses, live events a supportive community.
thorben-janssen.com
January 21, 2025 at 10:22 AM
And here's an article that goes deeper into Hibernate's and Jakarta Persistence's mapping of dates and timestamps:
thorben-janssen.com/hibernate-jp...
Date and Time Mappings with Hibernate and JPA
Databases and Java support various data types for date and time information. With Hibernate and JPA you can map almost all of them. Let me show you how.
thorben-janssen.com
December 4, 2024 at 3:11 PM
TimeZoneStorageType.DEFAULT:

Introduced as the new default in Hibernate 6.2.

Depends on the database dialect:
TimeZoneStorageType.NATIVE if dialect supports TIMESTAMP_WITH_TIMEZONE
TimeZoneStorageType.NORMALIZE_UTC if dialect doesn't support TIMESTAMP_WITH_TIMEZONE
December 4, 2024 at 3:11 PM
TimeZoneStorageType.AUTO:

Depends on the database dialect:
TimeZoneStorageType.NATIVE if dialect supports TIMESTAMP_WITH_TIMEZONE
TimeZoneStorageType.COLUMN if dialect doesn't support TIMESTAMP_WITH_TIMEZONE
December 4, 2024 at 3:11 PM
TimeZoneStorageType.COLUMN:

Hibernate stores the timestamp without timezone information and the timezone’s offset to UTC in separate database columns.

Don't use it for future timestamps because timezone rules can change.
December 4, 2024 at 3:11 PM
TimeZoneStorageType.NORMALIZE_UTC:

Hibernate normalizes the timestamp to UTC.
This avoids the issues of TimeZoneStorageType.NORMALIZE.
December 4, 2024 at 3:11 PM
TimeZoneStorageType.NORMALIZE:

Hibernate normalizes the timestamp to your local timezone. This can cause issues if your application runs in a timezone with DST or you want scale your application horizontally.

This is the same handling as in Hibernate 5.

Default in Hibernate 6.0 and 6.1.
December 4, 2024 at 3:11 PM