package com.jeecms.common.util;
import org.hibernate.Session;
import org.hibernate.internal.SessionImpl;
import com.alibaba.druid.util.StringUtils;
/**
* hibernate方言BUG修复
* @author
* @create 2018年3月26日 下午1:58:58
*/
public class DialectBugFix {
private Session session;
private String dialectName;
public DialectBugFix(Session session){
this.session = session;
getDbTypName();
}
/**
* 获取数据库名称类型
* @return
*/
private String getDbTypName(){
dialectName = ((SessionImpl)session).getFactory().getDialect().getClass().getName();
return dialectName;
}
/**
* 主要针对oracle的HOUR BUG进行修复
* @param properties
* @return
*/
public String hqlHour(String properties){
StringBuilder result = new StringBuilder();
if(StringUtils.isEmpty(properties)){
return null;
}
if(dialectName.toUpperCase().indexOf("ORACLE")>=0){
//oracle
result.append("TO_CHAR(").append(properties).append(",'hh24')");
}else{
result.append("HOUR(").append(properties).append(")");
}
return result.toString();
}
}
这是一个修复bug的工具类,用的时候直接new DialectBugFix(this.getSession()).hqlHour("ext.releaseDate"),作为字符串拼接到HQL就可以了 |
|