title: Hibernate saves/retrieves date minus day if application uses another timezone than MySQL
body: <p>I have an application started on tomcat on MACHINE_A with timezone GMT+3.</p>
  
  <p>I use remote MySQL server started on MACHINE_B with timezone UTC.</p>
  
  <p>We use spring-data-jpa for persistence.</p>
  
  <p>As an example of the problem, I will show the repository:</p>
  
  <pre><code>public interface MyRepository extends JpaRepository&lt;MyInstance, Long&gt; {
      Optional&lt;MyInstance&gt; findByDate(LocalDate localDate);
  }
  </code></pre>
  
  <p>If I pass localDate for <code>2018-09-06</code>, I get entities where the date is <code>2018-09-05</code>(previous day)</p>
  
  <p>In the logs I see:  </p>
  
  <pre><code>2018-09-06 18:17:27.783 TRACE 13676 --- [nio-8080-exec-3] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [DATE] - [2018-09-06]
  </code></pre>
  
  <p>I googled that question a lot and found several articles with the same content(for example <a href="https://moelholm.com/2016/11/09/spring-boot-controlling-timezones-with-hibernate/" rel="noreferrer">https://moelholm.com/2016/11/09/spring-boot-controlling-timezones-with-hibernate/</a>)</p>
  
  <p>So, I have the following <code>application.yml</code>:</p>
  
  <pre><code>spring:
    datasource:
      url: jdbc:mysql://localhost:3306/MYDB?useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC
      username: root
      password: *****
    jpa:
      hibernate:
        naming:
          physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
      properties:
        hibernate:
          show_sql: true
          use_sql_comments: true
          format_sql: true
          type: trace
          jdbc:
            time_zone: UTC
  </code></pre>
  
  <p>But it doesn't help.</p>
  
  <p>We use the following connector:</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.12&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>How can I resolve my problem?</p>
  
  <h2>P.S.</h2>
  
  <p>I tried to run both applications with the same time zone. In this case, everything works as expected.</p>
  
  <h2>P.S.2</h2>
  
  <p>I tried to use MySQL driver 6.0.6 version but it doesn't change anything.</p>