Hibernate - Chinese Encoding

 

First,  in hibernate.cfg.xml :

<property name="connection.url">jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8</property> 

 

Second, if you got something like "Incorrect string value: '\xE6\x9B\xB9\xE5\x86\xAC...' for column ...",then in Terminal:

mysql> alter database YOUR_DB_NAME character set utf8 

 

and recreate the tables , in hibernate.cfg.xml :

<property name="hbm2ddl.auto">create</property>  <!-- update -->

 

 


 

 

Chinese Encoding in HQL in hibernate.cfg.xml:

 

<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>

<property name="query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</property>

  

(Config these above or not) In Myeclipse console , you will see the format sql with "??" on behalf of Chinese value, nerver mind , the result is correct .

 

 

 

 

posted @ 2013-09-16 15:04  makemelike  阅读(233)  评论(0编辑  收藏  举报