在Hibernate配置文件中加入下面代碼:
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
如果是Spring+Hibernate開發(fā),則在定義Hibernate配置屬性時候加入:
<property name="hibernateProperties">
<props>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
</props>
</property>
設(shè)定數(shù)據(jù)庫連接方式是UTF-8。例如連接MYSQL時配置URL如下:這是在hibernate.cfg.xml文件里設(shè)置:jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8或加兩個屬性
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">UTF-8</property>
注意,上述寫法是hibernate的hibernate.cfg.xml寫法.最后要注意的是在tomcat中&要寫成&即可。