title: UTF - 8 with JPA and Glassfish 4.0
body: <p>I am having difficulties with UTF-8 characters. This is a simple JSF project. I use JSF 2.2 and Glassfish 4.0</p>
  
  <p>I have a method where I go:</p>
  
  <pre><code>em.persist(user);
  </code></pre>
  
  <p>When I debug</p>
  
  <pre><code>user.getName()
  </code></pre>
  
  <p>in this point, I can see the utf-8 characters in my IDE. Also I keep the string in a session - bean and I can see them on the browser fine as well. </p>
  
  <p>Only when they are persisted to DB, they are persisted as: ?????</p>
  
  <p>I can also edit the DB myself and save utf-8 characters. What I mean is, my SQL configuration is good for UTF-8.</p>
  
  <p>The problem is somewhere in JPA. </p>
  
  <p>This is what I have tried: ( all together: )</p>
  
  <p>persistence.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"&gt;
      &lt;persistence-unit name="Persistence" transaction-type="JTA"&gt;
          &lt;jta-data-source&gt;fus&lt;/jta-data-source&gt;
          &lt;class&gt;com.tugay.fup.core.model.User&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="javax.persistence.jdbc.url"
                    value="jdbc:mysql://localhost:3306/fus?useUnicode=yes&amp;amp;characterEncoding=UTF-8"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>This is glassfish-web.xml:</p>
  
  <pre><code>&lt;glassfish-web-app&gt;
      &lt;parameter-encoding default-charset="UTF-8"/&gt;
  &lt;/glassfish-web-app&gt;
  </code></pre>
  
  <p>And I am using EntityManager managed by container (transaction type = JTA)</p>
  
  <p>So in JDBC connection pools in Glassfish I have:</p>
  
  <pre><code>jdbc:mysql://localhost:3306/fus?useUnicode=true&amp;connectionCollation=utf8_general_ci&amp;characterSetResults=utf8
  </code></pre>
  
  <p>for: property: URL...</p>
  
  <p>However none of these help.</p>
  
  <p>Still characters not persisted correctly.</p>