Open kdubb opened 2 months ago
/cc @DavideD (hibernate-reactive), @gavinking (hibernate-reactive)
It should be noted that due to this issue and the inability to set the timezone for all configurations (see #43578), we ultimately abandoned using Hibernate's @CreationTimestamp
and @UpdateTimestamp,
which use the cached Clock
with the default time zone.
Set those two properties [1][2] and try again:
quarkus.hibernate-orm.mapping.timezone.default-storage=normalize
quarkus.hibernate-orm.jdbc.timezone=UTC
[1] https://quarkus.io/guides/all-config#quarkus-hibernate-orm_quarkus-hibernate-orm-mapping-timezone-default-storage [2] https://quarkus.io/guides/hibernate-reactive
It'll take me a bit to test this. I am currently a bit swamped and as I said, we abandoned any use of the Clock in Hibernate and instead made a base class to handle the creation and update of timestamps.
Describe the bug
Hibernate Reactive stores a
Clock
for use when injecting temporal values (e.g.,@CurrentTimestamp
or@CreationTimestamp
).This means the only way to set the time zone to UTC is to use system properties and/or the environment, which is painful. It requires you to update multiple build tasks (in Gradle) and ensure it's set properly in production before starting the app.
Also, there appears to be a
hibernate.testing.clock
property it checks during its Clock caching, but I have found no way to set that in Hibernate Reactive.Expected behavior
Users have an easy way to set the clock to UTC for dev and, more importantly, testing.
During my experience in tracking this down, the easiest method was thought to be using
@QuarkusMain
or@Observes StartupEvent,
but neither of these works because the Clock is cached prior to application code getting control.Actual behavior
The Clock is cached before any code can run.
This leaves the developer tracking down which build tasks need to be configured with JVM args to set the clock to their chosen timezone.
Additionally, when running without a build tool, you need to set the timezone via JVM args as well.
How to Reproduce?
@Entity
with@CreationTimestamp
./gradlew -Duser.timezone=UTC quarkusDev
orquarkus -Duser.timezone=UTC dev
Output of
uname -a
orver
macOS 14.6.1
Output of
java -version
21.0.1
Quarkus version or git rev
3.15.1
Build tool (ie. output of
mvnw --version
orgradlew --version
)Gradle 8.9
Additional information
No response