When Hibernate writes a Java Calendar object to an SQL TIMESTAMP column, to which time zone does it adjust the date, that of the computer or that specified in the c
If you don't want to write the code yourself, you can just use the open source library DbAssist. After applying this fix, the dates in the database will be treated by JDBC and then Hibernate as UTC, so you do not even have to change your entitiy classes.
For example, if you are using JPA Annotations with Hibernate 4.3.11, add the following Maven dependency:
com.montrosesoftware
DbAssist-4.3.11
1.0-RELEASE
Then you just apply the fix:
For Hibernate + Spring Boot setup, add the @EnableAutoConfiguration annotation before the application class.
For HBM files, you have to change the entity mapping files to map Date types to the custom one:
If you want to learn more about how to apply the fix for different Hibernate versions (or HBM files), refer to the project's github. You can also read more about the time zone shift issue in this article.