首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

hibernate中依照中文拼音排序

2012-08-10 
hibernate中按照中文拼音排序??/** * MySQLExtendDialect.java of new_dlog_cn * 作者: Winter Lau * 时间

hibernate中按照中文拼音排序

?

?

/** * MySQLExtendDialect.java of new_dlog_cn * 作者: Winter Lau * 时间: 2009-4-13 * 项目主页: <a href="http://www.dlog4j.com/">http://www.dlog4j.com</a> */package com.dlog4j.tester;import org.hibernate.Hibernate;import org.hibernate.dialect.*;import org.hibernate.dialect.function.SQLFunctionTemplate;/** * MySQL扩展方言 * @author Winter Lau */public class MySQLExtendDialect extends MySQLDialect {public MySQLExtendDialect(){super();registerFunction("convert_gbk",                  new SQLFunctionTemplate(Hibernate.STRING, "convert(?1 using gbk)") );}}

?

需要在hibernate.properties中更改hibernate.dialect方言字段:

hibernate.dialect=com.dlog4j.tester.MySQLExtendDialect


然后hql就可以这么写:"from ProductLine p order by convert_gbk(p.name) asc

?

?

转自:http://www.oschina.net/code/snippet_12_1094

参考:http://raywithu.iteye.com/blog/1139332


热点排行