保存Č,Ć字符的Hibernate DataException

时间:2017-09-04 09:31:54

标签: java sql hibernate exception

正如标题所说,我正在使用Hibernate ORM,每当我尝试用Č或save保存某些内容时,hibernate抛出“无法执行查询”错误。我使用utf8,Š,Ž,Đ字符工作得很好。我迷路了......这是cfg文件:

<property name="connection.url">jdbc:mysql://localhost:3306/eventi_orm</property>
    <property name="connection.username">root</property>
    <property name="connection.password"></property>
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.CharSet">utf8</property>
    <property name="hibernate.connection.characterEncoding">utf8</property>
    <property name="hibernate.connection.useUnicode">true</property>
    <property name="show_sql">true</property>
    <property name="format_sql">false</property>

这是输出:

Exception in thread "AWT-EventQueue-0" org.hibernate.exception.DataException: could not execute statement
...
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect string value: '\xC4\x87' for column 'name' at row 1

1 个答案:

答案 0 :(得分:0)

对不起,伙计们,这是一个愚蠢的疏忽。我在hibernate cfg文件中指定了utf8,但在创建数据库时忘了这么做。