/**
* 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
本文介绍了一种针对MySQL方言的扩展实现方法,通过自定义Hibernate方言类实现字符串转换功能,并提供了具体的代码实例及配置说明。
4428

被折叠的 条评论
为什么被折叠?



