Menu ▾ ▴

#1763 LocalDate/LocalDateTime binding changes historical date fields

version 2.5.x
open-fixed
None
5
5 hours ago
2026-11-13
No

Tested with both 2.7.5 RC3 and trunk r6855.

Binding LocalDate and LocalDateTime through PreparedStatement.setObject with Types.DATE / Types.TIMESTAMP changes their date fields for a date before the Gregorian cutover. Binding 1582-10-04 produces the SQL-visible date 1582-09-24. Inserting the same fields as SQL literals and reading them through the same typed getters returns 1582-10-04 correctly.

The attached reproducer uses JDBC and an in-memory HSQL database, with no ORM or other library. It fails in both UTC and America/Denver JVMs and does not require DST, a session timezone change, or a Calendar parameter.

Environment and tested builds

  • Eclipse Temurin OpenJDK 25+36-LTS, macOS, checked 2026-11-13.
  • Released org.hsqldb:hsqldb:2.7.4: reproduced.
  • Current published development jar hsqldb-2.7.5-ReleaseCandidate3.jar, listed 2026-09-07: reproduced.
  • Current SVN trunk r6855: reproduced after compiling the engine/JDBC classes with the upstream Ant classes target. This is a classpath reproduction using those classes, not a claim about a full distribution or module-path build.
  • Each build was tested in a separate JVM with user.timezone=UTC and user.timezone=America/Denver. All six runs show the same field changes.

Steps to reproduce
Put the attached HsqlHistoricalDateReproducer.java next to the HSQL jar, then run:

javac HsqlHistoricalDateReproducer.java
java -Duser.timezone=UTC -cp .:hsqldb-2.7.5-ReleaseCandidate3.jar HsqlHistoricalDateReproducer
java -Duser.timezone=America/Denver -cp .:hsqldb-2.7.5-ReleaseCandidate3.jar HsqlHistoricalDateReproducer

The reproducer creates a DATE and TIMESTAMP(9) column. Row 1 uses:

insert.setObject(1, LocalDate.of(1582, 10, 4), Types.DATE);
insert.setObject(2, LocalDateTime.of(1582, 10, 4, 12, 34, 56), Types.TIMESTAMP);

Row 2 uses SQL DATE/TIMESTAMP literals with those same fields. Both rows are then read using getObject(..., LocalDate.class), getObject(..., LocalDateTime.class), and independent SQL CAST(... AS VARCHAR) projections. The program throws AssertionError if any returned fields differ from the input.

Expected behavior
Both rows retain date 1582-10-04 and timestamp 1582-10-04T12:34:56. Java Time binding and SQL literals should agree for these SQL-accepted date/time fields.

Actual behavior (all six runs)
id=1 date=1582-09-24 timestamp=1582-09-24T12:34:56 SQL_DATE=1582-09-24 SQL_TIMESTAMP=1582-09-24 12:34:56.000000000
id=2 date=1582-10-04 timestamp=1582-10-04T12:34:56 SQL_DATE=1582-10-04 SQL_TIMESTAMP=1582-10-04 12:34:56.000000000
java.lang.AssertionError: Binding LocalDate/LocalDateTime must retain their date fields

Source-level explanation
In trunk r6855, DateTimeType.convertJavaToSQL(SessionInterface, LocalDate) delegates via LocalDate.atStartOfDay() to the LocalDateTime overload. Its DATE / TIMESTAMP route at approximately line 1085 computes ldt.toEpochSecond(ZoneOffset.UTC), using the Java Time proleptic Gregorian calendar.

DateTimeType.toLocalDate / toLocalDateTime, at approximately lines 3094 / 3107, instead recover fields through session.getCalendarGMT(). Session.getCalendarGMT(), at approximately line 1888, constructs a default GregorianCalendar without changing its Julian/Gregorian cutover. HsqlDateTime's SQL string parsing/formatting also uses that legacy calendar model. The inconsistent calendar interpretation explains the ten-day shift for the example.

This identifies an inconsistency, not a recommendation to change the engine's existing stored-date interpretation globally. Aligning valid Java Time input fields with SQL-literal input should avoid changing the meaning of existing rows. I have not identified the introducing revision.

Related reports checked

  • 1701: https://sourceforge.net/p/hsqldb/bugs/1701/


    Addresses LocalTime and LocalDateTime errors around DST; marked open-fixed, with the fix committed on 2024-04-29. Its attached reproducer chooses a future DST gap rather than a historical date. That original attached reproducer completes without mismatch output on RC3 and r6855 in America/Denver.
  • 1702: https://sourceforge.net/p/hsqldb/bugs/1702/


    Despite its LocalDate title, the actual reproducer compares legacy Time with LocalTime and shows a one-hour discrepancy in a DST timezone. It is marked open-fixed, with the fix committed on 2024-04-29. The corresponding comparison, including the original untyped getObject read and a typed LocalTime read, returns 15:30:45 for every route on RC3 and r6855 in Pacific/Auckland.
  • 1550: https://sourceforge.net/p/hsqldb/bugs/1550/


    Related historical-calendar report, but in the opposite direction: reading a SQL-literal timestamp before 1582 through getObject(LocalDateTime.class). It was fixed in 2019 and verified against r6017. A SQL-literal extraction control using its 1066-10-14 example passes on RC3 and r6855. The current report concerns the remaining Java Time binding route; the SQL-literal control also passes in the attached reproduction.
  • 1737: https://sourceforge.net/p/hsqldb/bugs/1737/


    Concerns BCE-era values and is open-later. This report uses AD 1582, within the maintainer-described 0001..9999 SQL range.

I did not find an existing report covering this current typed-binding case in the tracker searches performed. Please link or classify this as a regression/follow-up if it belongs with an earlier report.

Attachments
HsqlHistoricalDateReproducer.java is the minimal standalone reproduction. The accompanying evidence bundle contains all six reproduction logs, results for the earlier-issue controls, environment/build identification and checksums. No Hibernate code or dependency is required.

2 Attachments

Discussion

  • Fred Toussi

    Fred Toussi - 2026-11-13
    • assigned_to: Fred Toussi
     
  • Fred Toussi

    Fred Toussi - 2026-11-13

    Thanks for the report. I don't think this issue has come up before. It should get fixed very soon.

     
    🎉
    1
  • Steve Ebersole

    Steve Ebersole - 2026-11-13

    Small typo in the title, but I am not able to edit it - sorry

     
  • Fred Toussi

    Fred Toussi - 2026-11-13
    • summary: ocalDate/LocalDateTime binding changes historical date fields --> LocalDate/LocalDateTime binding changes historical date fields
     
  • Fred Toussi

    Fred Toussi - 5 hours ago
    • status: open --> open-fixed
     
  • Fred Toussi

    Fred Toussi - 5 hours ago

    Committed to SVN.

     

Log in to post a comment.