There seems to be a problem with the LocalDate in a MySQL database. Depending on the set time zone in the application the persisted date is wrong.
LocalDate AFAIK should not be affected by time zones at all. It should just use exactly the date provided and store it, but this is not the case.
This is quite difficult to track down, so I have made a test project that shows the problem in a unit test. Docker is required for this, as it spins up a testcontainers mysql database. Please run the test in
TimezoneMysqlBugApplicationTests and have a look at the
@BeforeEach and the
timezone-mysql-bug.zip (81.4 KB)
I guess the problem is somewhere in the JPA (EclipseLink) implementation.
EDIT: Ok, the problem is probably not EclipseLink - following SQL is found in the logs:
08:35:37.671 DEBUG eclipselink.logging.sql - <t 619529602, conn 300612436> INSERT INTO TEST_LOCAL_DATE_ENTITY (ID, LOCAL_DATE, NAME) VALUES (?, ?, ?) bind => [a3dff467875b43da67794d629ea51441, 2022-02-01, Test1]
(when provided a 2022-02-01 date)