日期:2014-05-16 浏览次数:20497 次
SQL异常信息:
[11-11-15 14:43:29:203 CST] 00000023 SystemOut ? ??O - 在 SELECT 子句、HAVING 子句 或 ORDER BY 子句中指定的以 "ID" 开始的表达式未在 GROUP BY 子句中指定,
或者它在 SELECT 子句、HAVING 子句或 ORDER BY 子句中,具有列函数,但未指定 GROUP BY 子句。. SQLCODE=-119, SQLSTATE=42803, DRIVER=3.62.56
?
Java代码:
?
public ItemPage getAlarmInfoPage(String systemId, String ipAddr, int pageNo, int pageSize) {
String queryHql = "from AlarmInfo t where 1=1 ";
if(systemId != null && !"".equals(systemId.trim())){
queryHql += "and t.systemId "+LikeEscape.likeEscapeParam(systemId);
}
if(ipAddr != null && !"".equals(ipAddr.trim())){
queryHql += "and t.ipAddr "+LikeEscape.likeEscapeParam(ipAddr);
}
queryHql += " ORDER BY t.id";
String countHql = "select count(*) "+queryHql;
return query(queryHql, countHql, pageNo==0? 1:pageNo, pageSize==0?10:pageSize);
}
?
分析:
以上期望是分页查询AlarmInfo的记录,并且查询结果根据ID来进行排序,在Hibernate中生成的DB2方言为:? ?
[11-11-15 17:23:12:234 CST] 0000002a SystemOut ? ? O Hibernate:?
select
? ? ? ? *?
? ? from
? ? ? ? ( select
? ? ? ? ? ? rownumber() over(
? ? ? ? order by
? ? ? ? ? ? alarminfo0_.ID) as rownumber_,
? ? ? ? ? ? alarminfo0_.ID as ID0_,
? ? ? ? ? ? alarminfo0_.ENTI_ID as ENTI2_0_,
? ? ? ? ? ? alarminfo0_.ENTI_CODE as ENTI3_0_,
? ? ? ? ? ? ala