title: Java EE, Hibernate, MySql UTF-8 query doesn't work
body: <p>So I have set up hibernate with Wildfly and MySql.</p>
  
  <p>Querying works, but have problem querying UTF-8 character names.</p>
  
  <p>On MySql:</p>
  
  <pre><code>SELECT * FROM users WHERE firstname = "ნიკა";
  </code></pre>
  
  <p>Doesn't result in empty set.</p>
  
  <p>While in java:</p>
  
  <pre><code>Session session = HibernateUtils.getSession();
  
  String name = request.getParameter("name");
  
  CriteriaBuilder builder = session.getCriteriaBuilder();
  
  CriteriaQuery&lt;UsersEntity&gt; query = builder.createQuery(UsersEntity.class);
  Root&lt;UsersEntity&gt; usersRoot = query.from(UsersEntity.class);
  query.select(usersRoot)
          .where(builder.equal(usersRoot.get("firstname"), name));
  
  List&lt;UsersEntity&gt; list = session.createQuery(query).list();
  
  session.close();
  
  writeUsers(list, response.getWriter());
  </code></pre>
  
  <p>Results in an empty set when querying <code>localhost:8080/main?name=ნიკა</code></p>
  
  <p>How do I fix this ?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I also have issue that when querying all data and displaying them
  non english characters are replaced with question marks.</p>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>This code results in showing up question marks on browser:</p>
  
  <pre><code>response.getWriter().write("ნიკა ჩხარტიშვილი");
  </code></pre>
  
  <p>While this one works properly:</p>
  
  <pre><code>response.setCharacterEncoding("UTF-8");
  response.getWriter().write("ნიკა ჩხარტიშვილი");
  </code></pre>
  
  <p>When querying database with this query <code>SELECT * FROM users WHERE username='ნიკა'</code> database receives question marks instead of <code>ნიკა</code> (That's what shows up in wireshark).</p>
  
  <p>I think it's wildfly issue because it received UTF-8 correctly but sends question marks unless it's specified to send UTF-8.</p>