title: Can't persist UTF-8 Symbols using MySQL, JPA, Hibernate
body: <p>there a lot of simillar questions but non of them solve my problem.
  I use JPA with hibernate and want to save UTF-8 characters.</p>
  <p>My maven dependencies are:</p>
  <pre><code>       &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
              &lt;version&gt;1.0.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
              &lt;version&gt;5.1.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;4.3.6.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.34&lt;/version&gt;
          &lt;/dependency&gt;
  
         &lt;dependency&gt;
              &lt;groupId&gt;com.mysema.querydsl&lt;/groupId&gt;
              &lt;artifactId&gt;querydsl-apt&lt;/artifactId&gt;
              &lt;version&gt;3.6.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.mysema.querydsl&lt;/groupId&gt;
              &lt;artifactId&gt;querydsl-jpa&lt;/artifactId&gt;
              &lt;version&gt;3.6.0&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  <p>So I use JPA 2.1 and QueryDSL 3.6.0.
  My persistance.xml is:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
  &lt;persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot;
           xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
           xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence
  
  
  http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot; version=&quot;1.0&quot;&gt;
  
  
  &lt;persistence-unit name=&quot;thePersistenceUnit&quot; transaction-type=&quot;RESOURCE_LOCAL&quot;&gt;
          &lt;properties&gt;
  
              &lt;property name=&quot;javax.persistence.jdbc.driver&quot; value=&quot;com.mysql.jdbc.Driver&quot;/&gt;
              &lt;property name=&quot;javax.persistence.jdbc.url&quot; value=&quot;jdbc:mysql://localhost:3306/newsDB?useUnicode=true&amp;amp;characterEncoding=UTF-8&quot;/&gt;
              &lt;property name=&quot;javax.persistence.jdbc.user&quot; value=&quot;root&quot;/&gt;
              &lt;property name=&quot;javax.persistence.jdbc.password&quot; value=&quot;root&quot;/&gt;
  
              &lt;!--Hibernate properties--&gt;
              &lt;property name=&quot;hibernate.show_sql&quot; value=&quot;false&quot;/&gt;
              &lt;property name=&quot;hibernate.format_sql&quot; value=&quot;false&quot;/&gt;
              &lt;property name=&quot;hibernate.hbm2ddl.auto&quot; value=&quot;create&quot;/&gt;
              &lt;property name=&quot;hibernate.dialect&quot; value=&quot;org.hibernate.dialect.MySQLDialect&quot;/&gt;
  
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  <p>Then I use XAMPP MySQL and Apache
  <img src="https://i.stack.imgur.com/a8uWz.png" alt="enter image description here" />
  <img src="https://i.stack.imgur.com/LQ1Jp.png" alt="enter image description here" /></p>
  <p>And add</p>
  <pre><code>port= 3306
  [client]
  default-character-set = utf8
  
  [mysqld]
  init-connect='SET NAMES utf8'
  character-set-server = utf8
  collation-server = utf8_general_ci
  
  [mysql]
  default-character-set = utf8
  </code></pre>
  <p>My DB Collation is:
  <img src="https://i.stack.imgur.com/JBvoy.png" alt="enter image description here" /></p>
  <p>And my table:
  <img src="https://i.stack.imgur.com/n0rlO.png" alt="enter image description here" /></p>
  <p>When I turn on the logger I saw:</p>
  <pre><code>TRACE [main] (BasicBinder.java:81) - binding parameter [1] as [VARCHAR] - [Xelian]
  TRACE [main] (BasicBinder.java:81) - binding parameter [2] as [VARCHAR] - [РћРїРёСЃР°РЅРёРµ]
  TRACE [main] (BasicBinder.java:81) - binding parameter [3] as [CLOB] - [Content of the text .Р§РёСЂРёРїР°С…Р°.]
  TRACE [main] (BasicBinder.java:81) - binding parameter [4] as [BIGINT] - [112]
  TRACE [main] (BasicBinder.java:81) - binding parameter [5] as [TIMESTAMP] - [Thu Jan 22 19:44:59 EET 2015]
  TRACE [main] (BasicBinder.java:81) - binding parameter [6] as [VARCHAR] - [Title]
  TRACE [main] (BasicBinder.java:81) - binding parameter [7] as [TIMESTAMP] - [Thu Jan 22 19:44:59 EET 2015]
  TRACE [main] (BasicBinder.java:81) - binding parameter [8] as [BIGINT] - [0]
  </code></pre>
  <p>You can see that the values are strange <strong>Р§РёСЂРёРїР°С…Р°.</strong>. And throught <em>phpmyadmin</em> I see:
  <img src="https://i.stack.imgur.com/WXNy9.png" alt="enter image description here" /></p>
  <p>But I when I edit it manually
  <img src="https://i.stack.imgur.com/AKhbL.png" alt="enter image description here" /></p>
  <p>You can see that my DB shows Cyrilic sumbols properlly. So I am wondering where is the problem.</p>