自定义 Hibernate 的 HQL 函数,hibernatehql,有时候我们使用一些数据库
分享于 点击 3932 次 点评:169
自定义 Hibernate 的 HQL 函数,hibernatehql,有时候我们使用一些数据库
有时候我们使用一些数据库特有的SQL语法跟HQL有冲突怎么办,看看这个
MySQLExtendDialect.java
/** * 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)") ); }}
用户点评