0

I got a problem when I was sorting customer list for the Chinese column with Hibernate, firstly, I tried to sort them by the simple HQL:

String hql = "FROM CUSTOMER ORDER BY name DESC";

I found the retrieved list didn't meet our requirement, I want to sort them with 26 letter spells, and then I googled the solution that it can be solved by SQL like:

String sql = "SELECT * FROM customer ORDER BY convert(name using gbk) DESC";

I posted it on MySQL command line and it selected the right-sorting result, but right now It still doesn't solve my problem since It doesn't work in Hibernate and I just want to use Hibernate (HQL) to query, so is there any way to do it? Or must I should develop a new database dialect to solve it?

Thanks.

SweetWisher ツ
  • 7,296
  • 2
  • 30
  • 74
Brady Zhu
  • 1,305
  • 5
  • 21
  • 43

1 Answers1

0

Try Using This, it might work for u as well, works for me!

SELECT * FROM customer  WHERE CONVERT(name USING gb2312) > '明'; 
SELECT * FROM customer ORDER BY CONVERT(name USING gb2312); 

The latter implicitly uses gb2312_chinese_ci but you could name another one for that charset, too.

Digital Alchemist
  • 2,324
  • 1
  • 15
  • 17