Question

I tried this code:

List resultList = new ArrayList();
Criteria criteria = createCriteria(SystemLogFile.class);
criteria.add(Expression.eq("clientId", clientId));
criteria.addOrder(Order.desc("systemLogFileId"));
if (page == -1) {
  resultList.add(criteria.setProjection(Projections.rowCount()).uniqueResult());
} else {
  criteria.setFirstResult(page * pageSize);
  criteria.setMaxResults(pageSize);
  resultList = criteria.list();
  setModelsListAsLoaded(resultList);
}
return resultList;

this code generate the following query:

select count(*) as y0_ from krn_system_log_file this_ where this_.CLIENT_ID=? order by this_.SYSTEM_LOG_FILE_ID desc

this works with oracle and mysql but not with db2! I get this error msg: Caused by: com.ibm.db2.jcc.am.io: DB2 SQL Error: SQLCODE=-119, SQLSTATE=42803, SQLERRMC=SYSTEM_LOG_FILE_ID, DRIVER=3.57.82

Was it helpful?

Solution

SQL Code -119 means:

An expression starting with expression-start specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified.

In DB2, if you want to order by this_.SYSTEM_LOG_FILE_ID, then that has to be in the GROUP BY clause. I don't use Hibernate, but can you add the GROUP BY to your criteria object?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top