From ee66a9330266590bab6903ce25bb3189db766d42 Mon Sep 17 00:00:00 2001 From: Gavin Date: Tue, 6 Dec 2022 17:40:58 +0100 Subject: [PATCH] HHH-15828 fix setting TIMEZONE_DEFAULT_STORAGE to COLUMN --- .../boot/internal/MetadataBuilderImpl.java | 10 +- .../process/spi/MetadataBuildingProcess.java | 4 +- ...ractDelegatingMetadataBuildingOptions.java | 6 + .../boot/spi/MetadataBuildingOptions.java | 3 + .../hibernate/cfg/AbstractPropertyHolder.java | 191 +++++++++--------- .../org/hibernate/cfg/AnnotationBinder.java | 78 ++++--- .../cfg/annotations/BasicValueBinder.java | 7 +- .../type/descriptor/jdbc/InstantJdbcType.java | 1 - 8 files changed, 164 insertions(+), 136 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java index 9743ec5935..062e760a1a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java @@ -746,10 +746,11 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont @Override public TimeZoneStorageStrategy getDefaultTimeZoneStorage() { - return toTimeZoneStorageStrategy( getTimeZoneSupport( serviceRegistry ) ); + return toTimeZoneStorageStrategy( getTimeZoneSupport() ); } - private static TimeZoneSupport getTimeZoneSupport(StandardServiceRegistry serviceRegistry) { + @Override + public TimeZoneSupport getTimeZoneSupport() { try { return serviceRegistry.getService( JdbcServices.class ) .getDialect() @@ -759,6 +760,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont return TimeZoneSupport.NONE; } } + private TimeZoneStorageStrategy toTimeZoneStorageStrategy(TimeZoneSupport timeZoneSupport) { switch ( defaultTimezoneStorage ) { case NATIVE: @@ -775,9 +777,11 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont case AUTO: switch (timeZoneSupport) { case NATIVE: + // if the db has native support for timezones, we use that, not a column return TimeZoneStorageStrategy.NATIVE; case NORMALIZE: case NONE: + // otherwise we use a separate column return TimeZoneStorageStrategy.COLUMN; default: throw new HibernateException( "Unsupported time zone support: " + timeZoneSupport); @@ -785,9 +789,11 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont case DEFAULT: switch (timeZoneSupport) { case NATIVE: + // if the db has native support for timezones, we use that, and don't normalize return TimeZoneStorageStrategy.NATIVE; case NORMALIZE: case NONE: + // otherwise we normalize things to UTC return TimeZoneStorageStrategy.NORMALIZE_UTC; default: throw new HibernateException( "Unsupported time zone support: " + timeZoneSupport); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java index 83c9aa1f9d..870cb861f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java @@ -66,7 +66,7 @@ import static org.hibernate.internal.util.config.ConfigurationHelper.getPreferre import static org.hibernate.internal.util.config.ConfigurationHelper.getPreferredSqlTypeCodeForUuid; /** - * Represents the process of of transforming a {@link MetadataSources} + * Represents the process of transforming a {@link MetadataSources} * reference into a {@link org.hibernate.boot.Metadata} reference. Allows for 2 different process paradigms: