0

I've made an application in Java EE that uses Hibernate to communicate with MySQL. It works perfectly on my Windows development machine, but I have problem on debian, where the application is deployed.

When I search for keyword with Polish letters(like ł, ą, ć, ó etc,) the result is ok on Windows, but on server, where I have imported the database it does not work.

Hibernate query looks like this:

@NamedQuery(name = "Keyword.findByKeyword", query = "SELECT k FROM Keyword k WHERE k.keyword = :keyword")

and is called like this:

myEntityManager.createNamedQuery("Keyword.findByKeyword").setParameter("keyword", keyword).getSingleResult();

When I use mysql on debian via SSH and type in SELECT query manually:

SELECT * FROM keywords WHERE keyword = 'ser żółty';

it also works and return single result. Encoding and collations of tables and columns are also ok. In datasource configuration I've added

?UseUnicode=true&characterEncoding=utf8

parameters, but it also did not help. I thought that maybe there is a problem with encoding in data from request send by form, but the problem appears even if the parameter i.e. "ser żółty" is hardcoded in my repository class.

I also use Hibernate Search for indexing and the FullTextEntityManager return correct results with Polish letters.

I assume that there is some problem between Hibernate and MySQL, but I have no more ideas what could I change. Any suggestions?

Server Wildfly9.0.1, MySQL 5.6

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
swch
  • 1,432
  • 4
  • 21
  • 37
  • `SELECT hex(col)` from the table for 'ser żółty'. If it is correctly stored, then you will get `73657220C5BCC3B3C5827479`. That should give us a clue of what direction to turn next. – Rick James Sep 08 '15 at 22:43
  • Thanks for Your reply. I did SELECT hex(keyword) FROM keyword WHERE keyword = 'ser żółty'; and I got exactly 73657220C5BCC3B3C5827479. Any clues? – swch Sep 09 '15 at 06:05

1 Answers1

0

Ok the problem was in encoding on the mysql server level. It was set to latin1 by default. To fix this follow this question Change MySQL default character set to UTF-8 in my.cnf? and edit your my.cnf file.

Community
  • 1
  • 1
swch
  • 1,432
  • 4
  • 21
  • 37