MySQL与JPA:非法混合排序(utf8mb4_general_ci,IMPLICIT)和(utf8_general_ci,COERCIBLE) [英] MySQL with JPA: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE)

查看:3252
本文介绍了MySQL与JPA:非法混合排序(utf8mb4_general_ci,IMPLICIT)和(utf8_general_ci,COERCIBLE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够在我的数据库中存储 \ xF0 \ x9F \ x94 \ xA5 等字符,根据这篇文章需要 UTF8mb4 编码。

I need to be able to store characters like \xF0\x9F\x94\xA5 in my database, which, according to this post need UTF8mb4 encoding.

所以我用

CREATE DATABASE `myDB` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci

并在MySQL shell中验证它是否有效:

and verified in the MySQL shell if it was effective:

SHOW FULL COLUMNS FROM myTable;

+---------+------------------+--------------------+----
| Field   | Type             | Collation          | ...
+---------+------------------+--------------------+-----
| id      | int(10) unsigned | NULL               | ...   
| myColumn| text             | utf8mb4_general_ci | ...
+---------+------------------+--------------------+-----

到目前为止一切顺利。

运行我的程序后,我得到了例外

After running my program, I got this Exception:

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like'
Error Code: 1267

对于记录:我在使用GlassFish 3.1的web应用程序中使用Java Persistency API(JPA)。执行命名查询时会抛出 Exception

For the record: I am using the Java Persistency API (JPA) in my webapplication with GlassFish 3.1. The Exception gets thrown when executing a named query:

@NamedQuery(name = "myTable.findByMyColumn", query = "SELECT c FROM myTable c WHERE c.myColumn LIKE :myColumn")

但是,只有在查询的字符串实际包含那些已经使用的表情符号字符时才会出现错误( \ xF0 \ x9F \ x94 \ xA5

However, it appears that the error only occurs when the queried String actually contains those weired emoji characters (\xF0\x9F\x94\xA5)

这篇关于MySQL与JPA:非法混合排序(utf8mb4_general_ci,IMPLICIT)和(utf8_general_ci,COERCIBLE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆