首先保证整个项目使用统一的编码如gb2312或utf8,在这里我使用的数据库为mysql,安装时设置为utf8编码,gb2312也成,然后在
hibernate.cfg.xml文件中设置你所使用的编码:
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">utf8</property>
或在设置数据库连接时采用如:
<property name="connection.url">jdbc:mysql://localhost:3306/db_group?useUnicode=true&characterEncoding=UTF-8</property>
的方式