| This is not a Hibernate issue. I created a test case to replicate it . All in all, the same issue can be replicated with plain JDBC while using the same MySQL JDBC configuration properties. The problem here is caused by this parameter:
- serverTimezone=Europe/Berlin
According to MySQL JDBC Driver documentation, the role of this config is to: Override detection/mapping of time zone. Used when time zone from server doesn't map to Java time zone That's what causing the drifting between the local time zone and the server time zone. The actual conversation happens because the MysqlaSession#configureTimezone will dictate if we need to translate from the client TZ to the server TZ. So, all this happens inside the MySQL Driver, which is out of Hibernate control. Mixing time zones is always trouble. The vast majority of applications simply set all DB servers to UTC and set all Date/Times according to UTC. You can achieve this goal with the hibernate.jdbc.time_zone configuration property. So, you have two ways to fix this issue:
- Either, you remove the serverTimezone property from the MySQL URL
- Or, you keep the serverTimezone property, but then you need to set the JVM timezone to the same TZ.
|