OffsetDateTime fields persisted incorrectly with SQL Server DATETIMEOFFSET

Description

When mapping an OffsetDateTime field to an SQL Server DATETIMEOFFSET column, the value is saved incorrectly: The offset gets replaced by the JVM's default system time zone, resulting in a different point in time being persisted. The only instance when the persisted date is correct is when the original offset of the OffsetDateTime value is happens to be the same as the system time zone offset (i.e. OffsetDateTime vales with zero offset are saved correctly if and only if the system time zone is set to UTC).

I have created a test project to demonstrate using Testcontainers for the SQL Server dependency, so it should require zero setup provided that you already have a docker daemon running. Running mvn test should be all you have to do (takes a few minutes on first try for Docker magic to happen).

Find the test case here:
https://github.com/cwatzl/hibernate-sqlserver-testcase-HHH-13369-test-case-template-based

(UPDATE: rewrote the test case to be based on official unit test template without Spring dependencies)

Environment

Hibernate 5.3.9
SQL Server 2017 (Docker Image: mcr.microsoft.com/mssql/server:2017-latest-ubuntu)
Docker for Windows 18.09.2

Status

Assignee

Unassigned

Reporter

cwatzl

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure