Search code examples
mysqlhibernatenetbeansarabic

Why Hibernate saveOrUpdate fails for arabic data?


When I save arabic string, the result in the database MySQL is simply ?.

In the table structure the encoding of the column is UTF-8, there are other arabic data, which means the problem is coming from Hibernate 4.3, when I looked at the documentation Developer Guide there is only one subject related to encoding, UTF, Arabic.., they suggested puting @Nationalized annotation, I did that and it is not useful.

By debugging, the arabic string is still in the object until:

session.saveOrUpdate(myObj);

After that I dont know what happened.

I am developing on Netbeans, thank you for help.


Solution

  • Try to put below line in datasource by specifying useUnicode and characterEncoding.

    jdbc:mysql://localhost:3306/dbname?useUnicode=yes&characterEncoding=UTF-8
    

    If you are using spring boot put below line in application.properties file.

    spring.datasource.connectionProperties=useUnicode=true;characterEncoding=utf-8;
    

    See use-useunicode-yes-characterencoding-utf-8