Prefer Java Time handling for all temporal values

Description

Java Time is a better way to handle date/time information introduced in Java 8. However, Hibernate still uses java.util.Date (and variants) for handling values at the vm/jdbc boundary. We should switch this to use the Java Time variants.

Although JDBC did not add explicit methods for handling Java Time values, the spec did explicitly add them as allowable for getObject and setObject calls and requires drivers support them.

There are a few “layers“ to this which we can address iteratively -

  1. Create JdbcType variants for each Java Time contract (LocalDateJdbcType, …) with corresponding SqlTypes entries (LOCAL_DATE, …). These would use the JDBC get/setObject calls.

  2. Allow global opt-in to using these Java Time variants at the boundary.

  3. Change the corresponding JavaType implementations to use the new matching SqlTypes code for their JavaType#getRecommendedJdbcType when enabled globally.

This includes -

  1. new JdbcType impls

  2. new SqlTypes constants

  3. new flag hibernate.type.prefer_java_type_jdbc_types (see org.hibernate.cfg.MappingSettings#PREFER_JAVA_TYPE_JDBC_TYPES)

Activity

Steve EbersoleDecember 21, 2023 at 2:03 AM

I’ve implemented the first 3 items in the original list -

  1. Create JdbcType variants for each Java Time types

  2. Allow global opt-in to using these Java Time JdbcType variants

  3. Change the corresponding JavaType implementations to use the new matching SqlTypes code for their JavaType#getRecommendedJdbcType when globally enabled.

At the moment there is an open question about whether the global setting should be opt-in (disabled by default) or opt-out (enabled by default).

We’ll leave the original item #4 as a potential follow-up task - changing the behavior of JdbcType for DATE, TIME, TIMESTAMP to use LocalDate, LocalTime and Instant as the #getJdbcRecommendedJavaTypeMapping. This is really about the handling for selected values in native queries when no explicit typing is specified - returning LocalDate instead of Date, LocalTime instead of Time and Instant instead of Timestamp.

Fixed

Details

Assignee

Reporter

Created December 12, 2023 at 5:01 PM
Updated March 20, 2024 at 10:09 PM
Resolved February 26, 2024 at 3:57 PM