javaspring-bootjdbctemplateojdbc

Unexpected time component insertion when persisting Java LocalDate to Oracle DATE column with JdbcTemplate in Spring Boot 3.2.0


We have encountered an unexpected behavior when persisting a Java LocalDate value in an Oracle DATE column using JdbcTemplate in Spring Boot 3.2.0.

Prior to upgrading to Spring Boot 3.2.0, the time component of the persisted value was defaulted to 00:00:00 (midnight). However, after the upgrade, the time component is now defaulted to 12:00:00 (noon).

For example, consider the following table and class:

CREATE TABLE EXAMPLE (
  EXAMPLE_DATE DATE
);
@Repository
public class ExampleRepository {

  private final JdbcTemplate jdbcTemplate;

  public void insert() {

    final String sql = "INSERT INTO EXAMPLE (EXAMPLE_DATE) VALUES (?)";

    this.jdbcTemplate.update(sql, LocalDate.now());
  }
}

After inserting a LocalDate value using this class, the following data is persisted in the EXAMPLE table:

SELECT to_char(EXAMPLE_DATE, 'YYYY-MM-DD HH24:MI:SS') FROM EXAMPLE;

2024-01-10 12:00:00

With this Spring Boot version ojdbc11 is updated to 23.3.0.23.09.

Reinstalling ojdbc11 21.11.0.0 reverts the behavior, and the persisted time component is once again defaulted to 00:00:00.

Java version: 17

We would appreciate any insights into this unexpected behavior and how to resolve it.


Solution

  • This is a known issue with 23.3.0.23.09 release and it will be fixed in next release i.e 23.4 until then I would suggest you to keep using 21.11 release JDBC jars. Also, please note that 23.3.0.23.09 is a developer release, so you should avoid using it in production.