Hibernate之方言篇
Hibernate使用方言(dialect)来实现数据库的操作的跨平台性。
?
1、如何使用
使用者必须在hibernate的配置文件比如hibernate.cfg.xml里对所使用的hibernate方言加以设置。
public class MySQL5Dialect extends org.hibernate.dialect.MySQL5Dialect {public MySQL5Dialect(){super();//时间秒数比较函数,返回值为秒数,如果?1 > ?2,返回值为正数,反之为负数registerFunction("timediffsecond",new SQLFunctionTemplate(Hibernate.INTEGER,"time_to_sec(timediff(?1,?2))"));/** * 字符串定位函数,即子字符串是否在查询字符串中。 * 返回值为0:子字符串不在查询字符串中; * 返回值大于0:子字符串在查询字符串中. * 示例:locate(('bar', 'foobarbar'). */registerFunction("locate",new StandardSQLFunction("locate",Hibernate.INTEGER));}}?