Search code examples
hibernatejpawildflytimestamp-with-timezonewildfly-swarm

hibernate.jdbc.time_zone setting is ignored in Wildfly Swarm application


I am building an application using Wildfly Swarm (2017.11.0), which requires ZonedDateTime objects to be persisted in UTC.

Currently, I am using the ExamplesDS JTA data source and configured following property:

<property name="hibernate.jdbc.time_zone" value="UTC"/>

As the Swarm JPA dependency declares Hibernate 5.0.x and JPA 2.1 as dependencies, I manually included

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>5.2.12.Final</version>
</dependency>

and

<dependency>
 <groupId>javax.persistence</groupId>
 <artifactId>javax.persistence-api</artifactId>
 <version>2.2</version>
</dependency>

and set them to non-provided.

However, the property is completely ignored by Hibernate, which persists and fetches the time stamps as a ZonedDateTimewith local zone. Other properties inside the persistence.xml are correctly recognized.

At the moment, I am not sure where the issue is located and how to solve it. Also, when I am running Wildfly Swarm with the jvm argument -Duser.timezone=UTC, nothing changes. Is this maybe an issue of the ExamplesDS or is Wildfly Swarm ignoring my dependency declarations? If so, how can I ensure that Swarm uses the correct version?


Solution

  • In many aspects, WildFly Swarm behaves just like WildFly. You can't upgrade Hibernate/JPA like this, nor any other Java EE spec.

    There are probably ways to do it, such as changing directly the content of m2repo inside the Swarm uberjar, or manipulating with subsystems and modules, but you shouldn't expect that to work flawlessly.