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
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
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.
Thanks for the report. I don't think this issue has come up before. It should get fixed very soon.
Small typo in the title, but I am not able to edit it - sorry
Committed to SVN.