你能告诉我我在做什么错吗?
休眠版本:4.3.11.Final
MariaDb 10.3
在控制台中,我可以看到:
Dec 30, 2018 5:02:20 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper$StandardWarningHandler logWarning
WARN: Incorrect string value: '\xF0\x9F\x90\xB5 D...' for column 'nick' at row 1
hibernate.cfg.xml
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/dbname?autoReconnect=true&zeroDateTimeBehavior=convertToNull&useUnicode=true&character_set_server=utf8mb4</property>
<property name="hibernate.connection.username">login</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.CharSet">utf8mb4</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
当我通过PhpMyAdmin插入相同的值时,它可以正常工作。
答案 0 :(得分:0)
是的, MySQL 需要utf8mb4
的{{1}}。但外界称它为\xF0\x9F\x90\xB5
。
UTF-8
&character_set_server=utf8mb4
-> &
&
-> character_set_server=utf8mb4