0

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.

TiyebM
  • 2,684
  • 3
  • 40
  • 66

2 Answers2

2

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

Alien
  • 15,141
  • 6
  • 37
  • 57
  • 1
    Thank you, now my url is: `jdbc:mysql://localhost:3306/mydb?useUnicode=yes&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull` – TiyebM Dec 17 '18 at 08:55
0

you must specify charset for schema and table, just change your default charset of database, base on following below link :

Change MySQL default character set to UTF-8 in my.cnf?

if you read this link and change setting you must :

first : restart mysql or any other like this (systemctl start mysql)

second : drop your schema and database and tables then recreate it.

This work for persian language.

MostafaMashayekhi
  • 27,359
  • 3
  • 21
  • 39