views:

93

answers:

2

I have a db in production where all of my tables are using utf8 / utf8_general_ci encoding. This is basically working fine except in one scenario.

What happens is that ??? are being returned for some characters (Chinese, etc); however, they are also returned correctly for the same table but via a different criteria.

I've double checked the connection parameters from Hibernate to MySQL and they have the good charset set.

I cannot understand how this can be happening. The criteria that returns the bad characters is just a simple findById:

Criteria criteria = getHibernateSession().createCriteria(CalendarEvent.class);
criteria.add(Restrictions.eq("id", id));
return (CalendarEvent) criteria.uniqueResult();

This is only happening in production on Solaris - I cannot reproduce it locally.

+1  A: 

In your connection-string have you tried

jdbc:mysql://localhost/dbname?characterEncoding=utf8

or add JVM parameter -Dfile-encoding=utf-8 when starting your application / server

Bozho
yeah we have that already
wjp
check my update
Bozho
thanks Bozho, but I don't see how VM file encoding has an effect on hibernate (I will try though)
wjp
A: 

Try setting the following properties in your hibernate configuration file:

<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.characterEncoding">UTF-8</property>
<property name="hibernate.connection.charSet">UTF-8</property>
EJB
Hmm we don't have the useUnicode one (the others we do). I will try.
wjp