HHH-17559 - Prefer Java Time handling for all temporal values

This commit is contained in:
Steve Ebersole 2024-04-12 13:08:33 -05:00
parent add62a188b
commit a996b6514e
8 changed files with 20 additions and 31 deletions

View File

@ -100,7 +100,7 @@ public interface MetadataBuildingContext {
static boolean isPreferJavaTimeJdbcTypesEnabled(ConfigurationService configurationService) { static boolean isPreferJavaTimeJdbcTypesEnabled(ConfigurationService configurationService) {
return ConfigurationHelper.getBoolean( return ConfigurationHelper.getBoolean(
MappingSettings.PREFER_JAVA_TYPE_JDBC_TYPES, MappingSettings.JAVA_TIME_USE_DIRECT_JDBC,
configurationService.getSettings(), configurationService.getSettings(),
// todo : true would be better eventually so maybe just rip off that band aid // todo : true would be better eventually so maybe just rip off that band aid
false false

View File

@ -240,7 +240,7 @@ public interface MappingSettings {
* @since 6.5 * @since 6.5
*/ */
@Incubating @Incubating
String PREFER_JAVA_TYPE_JDBC_TYPES = "hibernate.type.prefer_java_type_jdbc_types"; String JAVA_TIME_USE_DIRECT_JDBC = "hibernate.type.java_time_use_direct_jdbc";
/** /**
* Indicates whether to prefer using SQL enums and the respective special JDBC types for binding/extracting * Indicates whether to prefer using SQL enums and the respective special JDBC types for binding/extracting

View File

@ -70,7 +70,7 @@ public interface JdbcTypeIndicators {
} }
/** /**
* @see org.hibernate.cfg.MappingSettings#PREFER_JAVA_TYPE_JDBC_TYPES * @see org.hibernate.cfg.MappingSettings#JAVA_TIME_USE_DIRECT_JDBC
*/ */
default boolean isPreferJavaTimeJdbcTypesEnabled() { default boolean isPreferJavaTimeJdbcTypesEnabled() {
return getCurrentBaseSqlTypeIndicators().isPreferJavaTimeJdbcTypesEnabled(); return getCurrentBaseSqlTypeIndicators().isPreferJavaTimeJdbcTypesEnabled();

View File

@ -12,7 +12,6 @@ import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.cfg.MappingSettings; import org.hibernate.cfg.MappingSettings;
import org.hibernate.community.dialect.AltibaseDialect; import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.DB2Dialect;
@ -22,12 +21,8 @@ import org.hibernate.dialect.HANADialect;
import org.hibernate.dialect.OracleDialect; import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.SybaseDialect; import org.hibernate.dialect.SybaseDialect;
import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.Value;
import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.java.LocalDateJavaType;
import org.hibernate.type.descriptor.jdbc.JavaTimeJdbcType; import org.hibernate.type.descriptor.jdbc.JavaTimeJdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.LocalDateJdbcType; import org.hibernate.type.descriptor.jdbc.LocalDateJdbcType;
@ -58,7 +53,7 @@ import static org.hibernate.type.descriptor.DateTimeUtils.roundToDefaultPrecisio
*/ */
@SuppressWarnings("JUnitMalformedDeclaration") @SuppressWarnings("JUnitMalformedDeclaration")
@ServiceRegistry( @ServiceRegistry(
settings = @Setting(name = MappingSettings.PREFER_JAVA_TYPE_JDBC_TYPES, value = "true") settings = @Setting(name = MappingSettings.JAVA_TIME_USE_DIRECT_JDBC, value = "true")
) )
@DomainModel( annotatedClasses = GlobalJavaTimeJdbcTypeTests.EntityWithJavaTimeValues.class ) @DomainModel( annotatedClasses = GlobalJavaTimeJdbcTypeTests.EntityWithJavaTimeValues.class )
@SessionFactory @SessionFactory

View File

@ -10,19 +10,11 @@ import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.cfg.MappingSettings; import org.hibernate.cfg.MappingSettings;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.jdbc.DateJdbcType; import org.hibernate.type.descriptor.jdbc.DateJdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.TimeJdbcType; import org.hibernate.type.descriptor.jdbc.TimeJdbcType;
@ -32,10 +24,7 @@ import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope; import org.hibernate.testing.orm.junit.DomainModelScope;
import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting; import org.hibernate.testing.orm.junit.Setting;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -43,7 +32,6 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.type.descriptor.DateTimeUtils.roundToDefaultPrecision;
/** /**
* Tests for "direct" JDBC handling of {@linkplain java.time Java Time} types. * Tests for "direct" JDBC handling of {@linkplain java.time Java Time} types.
@ -52,7 +40,7 @@ import static org.hibernate.type.descriptor.DateTimeUtils.roundToDefaultPrecisio
*/ */
@SuppressWarnings("JUnitMalformedDeclaration") @SuppressWarnings("JUnitMalformedDeclaration")
@ServiceRegistry( @ServiceRegistry(
settings = @Setting(name = MappingSettings.PREFER_JAVA_TYPE_JDBC_TYPES, value = "false") settings = @Setting(name = MappingSettings.JAVA_TIME_USE_DIRECT_JDBC, value = "false")
) )
@DomainModel( annotatedClasses = JavaTimeJdbcTypeBaselineTests.EntityWithJavaTimeValues.class ) @DomainModel( annotatedClasses = JavaTimeJdbcTypeBaselineTests.EntityWithJavaTimeValues.class )
@SessionFactory @SessionFactory

View File

@ -25,14 +25,10 @@ import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.type.SqlTypes; import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.jdbc.DateJdbcType;
import org.hibernate.type.descriptor.jdbc.JavaTimeJdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.LocalDateJdbcType; import org.hibernate.type.descriptor.jdbc.LocalDateJdbcType;
import org.hibernate.type.descriptor.jdbc.LocalDateTimeJdbcType; import org.hibernate.type.descriptor.jdbc.LocalDateTimeJdbcType;
import org.hibernate.type.descriptor.jdbc.LocalTimeJdbcType; import org.hibernate.type.descriptor.jdbc.LocalTimeJdbcType;
import org.hibernate.type.descriptor.jdbc.TimeJdbcType;
import org.hibernate.type.descriptor.jdbc.TimestampJdbcType;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope; import org.hibernate.testing.orm.junit.DomainModelScope;
@ -58,7 +54,7 @@ import static org.hibernate.type.descriptor.DateTimeUtils.roundToDefaultPrecisio
*/ */
@SuppressWarnings("JUnitMalformedDeclaration") @SuppressWarnings("JUnitMalformedDeclaration")
@ServiceRegistry( @ServiceRegistry(
settings = @Setting(name = MappingSettings.PREFER_JAVA_TYPE_JDBC_TYPES, value = "false") settings = @Setting(name = MappingSettings.JAVA_TIME_USE_DIRECT_JDBC, value = "false")
) )
@DomainModel( annotatedClasses = JavaTimeJdbcTypeTests.EntityWithJavaTimeValues.class ) @DomainModel( annotatedClasses = JavaTimeJdbcTypeTests.EntityWithJavaTimeValues.class )
@SessionFactory @SessionFactory

View File

@ -32,13 +32,19 @@ those intermediate forms.
For 6.5 this behavior is disabled by default. To opt-in, For 6.5 this behavior is disabled by default. To opt-in,
[source] [source,properties]
---- ----
hibernate.type.prefer_java_type_jdbc_types=true hibernate.type.java_time_use_direct_jdbc=true
---- ----
NOTE: The name of this setting has been changed from `hibernate.type.prefer_java_type_jdbc_types` as first introduced in 6.5 CR1 to avoid confusion with the numerous `hibernate.type.prefer_<xyz>` settings.
IMPORTANT: This feature is known to not work with the Sybase jConnect driver despite
this feature being part of JDBC since 4.2 (Java 8). We have notified the Sybase development team, but this seems unlikely to change.
It is expected the default will flip for 7.0. It is expected the default will flip for 7.0.
[[query-cache-layout]] [[query-cache-layout]]
== Configurable Query Cache Layout == Configurable Query Cache Layout

View File

@ -32,12 +32,16 @@ For 6.5 this behavior is disabled by default. To opt-in,
[source,properties] [source,properties]
---- ----
hibernate.type.prefer_java_type_jdbc_types=true hibernate.type.java_time_use_direct_jdbc=true
---- ----
See the link:{javadocs-url}/org/hibernate/cfg/MappingSettings.html#PREFER_JAVA_TYPE_JDBC_TYPES[setting Javadoc] for additional details. See the link:{javadocs-url}/org/hibernate/cfg/MappingSettings.html#PREFER_JAVA_TYPE_JDBC_TYPES[setting Javadoc] for additional details.
IMPORTANT: This feature is known to not work with the Sybase jConnect driver despite
this feature being part of JDBC since 4.2 (Java 8). We have notified the Sybase development team, but this seems unlikely to change.
[[query-cache-layout]] [[query-cache-layout]]
== Configurable Query Cache Layout == Configurable Query Cache Layout