`

Hibernate HQL支持convert对汉字排序

 
阅读更多
hql不支持utf-8的汉字按拼音排序,需要转换成gbk,这就要扩展数据库方言,用的是mysql数据库:
package com.jbms.util;

import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.function.SQLFunctionTemplate;

public class MySQLLocalDialect extends MySQLDialect {

public MySQLLocalDialect(){
super();
registerFunction("convert", new SQLFunctionTemplate(org.hibernate.Hibernate.STRING, "convert(?1 using ?2)") );
    }

}
同时修改数据库方言配置:
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
<!-- org.hibernate.dialect.MySQLDialect-->
com.jbms.util.MySQLLocalDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
参考:http://blog.sina.com.cn/s/blog_624a352c0100qkaq.html

http://www.oschina.net/bbs/thread/302

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics