0

JPA Order By with Character Set Issue.

I use spring-data-jpa and mysql 5.7. My db character set is utf8mb4 for I need store emoji in table.

Here is my table:

+--------------------+--------------+------+-----+-------------------+-----------------------------+
| Field              | Type         | Null | Key | Default           | Extra                       |
+--------------------+--------------+------+-----+-------------------+-----------------------------+
| id                 | varchar(50)  | NO   | PRI | NULL              |                             |
| name               | varchar(100) | NO   |     | NULL              |                             |
| content            | varchar(100) | NO   |     | NULL              |                             |
| status             | varchar(20)  | NO   | MUL | DEFAULT           |                             |
| type               | varchar(50)  | NO   | MUL | DEFAULT           |                             |
+--------------------+--------------+------+-----+-------------------+-----------------------------+

I want to select item and order by name with Chinese character order. Item name can be emoji and Chinese string.

I can do this if use native sql :

select * from item where name like ? order by convert(name using gbk);

Is it possible to use convert(name using gbk) in JPA Specification?

Sid
  • 31
  • 4
  • I doubt that JPA supports this, but why not just use a native query? JPA still plugs into native queries very well (if you check the documentation on that). – Tim Biegeleisen Jun 30 '21 at 03:46
  • 1
    Does this answer your question? [how to call the function that was using mysql keywords as parameters by the criteria query?](https://stackoverflow.com/questions/58709930/how-to-call-the-function-that-was-using-mysql-keywords-as-parameters-by-the-crit) – aatwork Jun 30 '21 at 04:25

0 Answers0