-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hibernate ORM graphql panache test fails if time zone is west of GMT #37659
Comments
/cc @FroMage (panache), @Sanne (hibernate-orm), @gsmet (hibernate-orm), @jmartisk (graphql), @loicmathieu (panache), @phillip-kruger (graphql), @yrodiere (hibernate-orm) |
FWIW See the note in https://docs.jboss.org/hibernate/search/7.0/reference/en-US/html_single/#mapping-legacy-date-time-apis (it's not specific to Hibernate Search). Bottom line: if someone wants to fix this without getting an urge to knock their head against a wall, I'd advise to start by using a date after 1900 and seeing if it fixes the problem. Only try to see what's going on if this doesn't fix the problem... |
I changed the date from Is there some way that we could specify that the time zone of the stored value is UTC? |
I'm also trying to create an isolated "scratch" test to see if I can reproduce the issue outside of h2. AFAICT, the test creates and populates the table using the local time zone, so I should in theory be able to create a |
We do to some extent IIRC, but as I said this conversion is complex and IMO impossible to get right. But more importantly, there's probably always been a drift when Hibernate ORM stores the value using JDBC; happily the drift occurs the other way when reading back. So the value stored in DB will not reflect exactly what you wrote. This is important because here you're using
Not for
No no, if you write and read through Hibernate ORM all's fine. It's just that your
As you wish, but you've been warned :) |
OK, I traced through all of the date conversion code in Hibernate. It appears that the bug is wholly in h2. By the time we select out the date, it's already incorrect (even if you don't account for So the next step is to find the problem on the h2 side... |
FWIW JDBC drivers have quite a few bugs like this (just look at that), so we generally consider ourselves happy when the bug when reading compensates the one when writing :) |
I think I've found the problem. Deep within the bowels of h2, there is a utility method like this which is used when a public static long getMillis(CastDataProvider provider, TimeZone tz, long dateValue, long timeNanos) {
return (tz == null ? provider != null ? provider.currentTimeZone() : DateTimeUtils.getTimeZone()
: TimeZoneProvider.ofId(tz.getID())).getEpochSecondsFromLocal(dateValue, timeNanos) * 1_000
+ timeNanos / 1_000_000 % 1_000;
} This here is where we end up in the wrong calendar system. However, we could potentially avoid this problem within Hibernate. If our output type is I guess this approach isn't universally supported by all JDBC drivers, but we should use it whenever it is supported to avoid this problem. Edit: just to clarify, the problem is fully on the select side. On insert, the date is added correctly in h2's internal packed form; it only becomes wrong once we select it out as a |
Fixes quarkusio#37659. A follow-up issue will be filed to revert this commit once ORM 7.x is integrated.
Note for posterity: to reproduce this issue, I believe that the current time in the time zone of the system must have a different day than UTC. As such the test may only fail at certain times of the day. In any event, the fix is to provide ad-hoc direct support for |
Describe the bug
Test fails if time zone is west of GMT:
Setting e.g.
TZ=Europe/Zurich
makes the problem go away.Expected behavior
Test should pass in all local time zones.
Actual behavior
The date is not mapped correctly, presumably because it is taking a
ZonedDateTime
from the local zone and then getting the date after mapping it to GMT.How to Reproduce?
Run
TZ=America/Chicago mvn install -rf :quarkus-integration-test-hibernate-orm-graphql-panache
after a clean build e.g.mvn clean && mvn install -DskipTests
.Output of
uname -a
orver
Darwin xxxx 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:28:45 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6020 arm64
Output of
java -version
openjdk 17.0.9 2023-10-17 OpenJDK Runtime Environment Temurin-17.0.9+9 (build 17.0.9+9) OpenJDK 64-Bit Server VM Temurin-17.0.9+9 (build 17.0.9+9, mixed mode)
Quarkus version or git rev
0d90b7c
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546) Maven home: /Users/david/local/apache-maven Java version: 17.0.9, vendor: Eclipse Adoptium, runtime: /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "14.1.2", arch: "aarch64", family: "mac"
Additional information
No response
The text was updated successfully, but these errors were encountered: