Every time a Java LocalDate field is being persisted to a MySQL Date field 1 day is being lost. For instance a Java value of 01 July 2019 would be saved as 30 June 2019 in the Date MySQL column. The MySQL database server is configured to have the 'system time zone' as CDT and I don't have permissions to change this.
The Java program is executed from Europe with the following persistence.xml configuration.
<property name="javax.persistence.jdbc.driver"
value="com.mysql.cj.jdbc.Driver" />
<property name="javax.persistence.jdbc.url"
value="...?useTimezone=true&useLegacyDatetimeCode=false&serverTimezone=America/Chicago&autoReconnect=true" />
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLInnoDBDialect" />
<property name="hibernate.jdbc.time_zone" value="America/Chicago"/>
The value America/Chicago was chosen because the database server is located in that region (MySQL is configured with the CDT time zone but the CDT abbreviation is not valid in Java)
I have tried without the useTimezone=true&useLegacyDatetimeCode=false and there was no difference. I have tried also with simultaneously having serverTimezone=UTC and hibernate.jdbc.time_zone as UTC and without luck also.
In pom.xml I'm using the following jdbc and hibernate versions.
<mysql-connector.version>8.0.18</mysql-connector.version>
<hibernate.version>5.4.6.Final</hibernate.version>
Using hibernate version 5.4.6 I understand that JPA 2.2 is supported which means that the LocalDate should be supported out of the box without any converter.
I'm not able to get it working. All the things tried were after reading similar issues on StackOverflow. Whatever I try the date will always come -1 day in the database.