thomas
thomas

Reputation: 1281

Issue with Character Set encoding for Emojis when using Mysql and Hibernate

I have an application coded with Spring/Hibernate/Spring Data/ Jpa

When I try to update an entity , I am getting this error :

[ERROR] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Incorrect string value: '\xEF\x83\xA8 Be...' for column 'description' at row 1

What characterset should I use in Mysql in order to get rid of this problem?

Thank you

Upvotes: 1

Views: 598

Answers (1)

Vlad Mihalcea
Vlad Mihalcea

Reputation: 153970

You should use the utf8mb4 MySQL Character Set which has also become the default one in MySQL 8.

Quoting the MySQL Server team post, if you want to use Emojis, then you need the utf8mb4 Character Set.

Even for English speaking markets, the prevalence of emojis as character input is driving adoption of utf8mb4 over utf8mb3 and latin1.

You can set the utf8mb4 Character Set using the following ALTER DATABASE SSL statement:

ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;

Upvotes: 1

Related Questions