title: LocalDate MySQL persistence comes back the date before
body: <p>I have seen this question posted a few times on StackOverflow, and it has been with mostly Spring Boot apps with Spring Boot Configuration.   I've followed all the steps, and I still have this issue.  If I can't get this resolved soon, I will have to go back to the old java.util.Date in order to persist my data to the database ... at least it worked without issues.  So, I have a Spring 5.1.2.Release app, with Hibernate 5.4.0.Final, the hibernate-java8 dependency, and the latest MySQL Connector 8.0.13.</p>
  
  <p>I understand from previous posts and other articles on the Net that if the database is set for UTC, but the App is running in another timezone, in my case GMT-5 for EST, then this problem might pop up.</p>
  
  <p>So, here are the technical details:
  My MySQL connection looks like:</p>
  
  <pre><code>hibernate.connection.url=jdbc:mysql://localhost:3306/my_db? 
  serverTimezone=UTC&amp;useLegacyDatetimeCode=false&amp;useTimezone=true
  </code></pre>
  
  <p>The connection string, is used in the applicationContext.xml:</p>
  
  <pre><code>&lt;bean id="dataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName"&gt;
          &lt;value&gt;${hibernate.connection.driver.class}&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="url"&gt;
          &lt;value&gt;${hibernate.connection.url}&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="username"&gt;
          &lt;value&gt;${hibernate.connection.username}&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="password"&gt;
          &lt;value&gt;${hibernate.connection.password}&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>My Hibernate properties in my applicationContext.xml look like:</p>
  
  <pre><code>&lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;
              &lt;prop key="hibernate.cglib.use_reflection_optimizer"&gt;${hibernate.cglib.use_reflection_optimizer}&lt;/prop&gt;
              &lt;prop key="useUnicode"&gt;true&lt;/prop&gt;
              &lt;prop key="useLegacyDatetimeCode"&gt;false&lt;/prop&gt;
              &lt;prop key="serverTimezone"&gt;UTC&lt;/prop&gt;
              &lt;prop key="useTimezone"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.jdbc.time_zone"&gt;UTC&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  </code></pre>
  
  <p>My Maven dependencies are:</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;8.0.13&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;5.4.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-java8&lt;/artifactId&gt;
          &lt;version&gt;5.4.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>My Entity Code is simple:</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "transaction_id")
  private long txId;
  
  @Column(name = "transaction_date")
  private LocalDate txDate;
  </code></pre>
  
  <p>I save my code to the database like this:</p>
  
  <pre><code>@Override
  public TxEntity create(TxEntity txEntity)
  {
      this.sessionFactory.getCurrentSession().save(txEntity);
      this.sessionFactory.getCurrentSession().flush();
      this.sessionFactory.getCurrentSession().refresh(txEntity);
      return txEntity;
  }
  </code></pre>
  
  <p>The database has "transaction_date" as a DATE field in MySQL.</p>
  
  <p>My Unit Test shows that I can create a new record, and I have set the date as follows:</p>
  
  <pre><code>      LocalDate today = LocalDate.now();
  </code></pre>
  
  <p>I persist the record, and when I test:</p>
  
  <pre><code>assertEquals(today, myRecord.getTransactionDate());
  </code></pre>
  
  <p>this fails, because I get the previous date.</p>
  
  <p>I thought that if I used the latest versions of Hibernate and the Hibernate-java8 I would be fine, but that's not the case.   I thought if I pulled in the latest JPA2.2 that would work, but it's not.  So, I think I am doing everything right, and I still have an issue.</p>
  
  <p>So, if there is anything you need to see, let me know and I can add it.  I think I am doing everything right, but if there is anything off I need to fix, please let me know.    And of course, I'll keep looking at this myself.</p>