0

As the title says, I'm using Hibernate ORM and whenever I try to save something with Č or Ć in it hibernate throws "couldn't execute query" error. I am using utf8, and Š, Ž, Đ characters work just fine. I'm lost...here is the cfg file:

<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>

And here is the output:

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
Goran Kovač
  • 105
  • 1
  • 12
  • "Data truncation" ... UTF-8 characters have variable length. BTW database (mysql) should be precisely configured, because of sorting and other problems. In ancient years we store utf-8 strigs in ASCII database columns, similar problem happens – Jacek Cz Sep 04 '17 at 09:35
  • I believe this is a same problem: https://stackoverflow.com/questions/2108824/mysql-incorrect-string-value-error-when-save-unicode-string-in-django – Andremoniy Sep 04 '17 at 09:36
  • Possible duplicate of [MySQL "incorrect string value" error when save unicode string in Django](https://stackoverflow.com/questions/2108824/mysql-incorrect-string-value-error-when-save-unicode-string-in-django) – Guillotine Sep 04 '17 at 09:40
  • @Goran- Try to use a DB client and insert a string containing Č and Ć into your database. If the error is still present then it's mostly likely that your DB isn't configured properly. – dsp_user Sep 04 '17 at 10:49

1 Answers1

0

Sorry guys, it was a silly oversight. I specified utf8 in a hibernate cfg file but forgot to do so when creating database.

Goran Kovač
  • 105
  • 1
  • 12