Suppose that I use IBM DB2 and I have criteriaQuery, which sets firstResult but not maxResults. For example:
{code} CriteriaQuery cq = em.getCriteriaBuilder().createQuery(Some.class); TypedQuery<Some> query = em.createQuery(cq); query.setFirstResult(1); query.getResultList(); {code}
this one fails on IBM DB2 with the stacktrace like below. Is it an expected behaviour for DB2 database or rather bug in Hibernate? Can Hibernate JPA implementation set some sensible default for "maxResults" if it's not provided in query?
{code} Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602) at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:492) at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:50) at org.myapp.MyApp.getResultList(MyApp.java:149) ... 37 more Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79) at org.hibernate.loader.Loader.getResultSet(Loader.java:2117) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1900) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1876) at org.hibernate.loader.Loader.doQuery(Loader.java:919) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) at org.hibernate.loader.Loader.doList(Loader.java:2617) at org.hibernate.loader.Loader.doList(Loader.java:2600) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429) at org.hibernate.loader.Loader.list(Loader.java:2424) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371) at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1326) at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87) at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606) at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483) ... 50 more Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-270, SQLSTATE=42997, SQLERRMC=63, DRIVER=4.19.26 at com.ibm.db2.jcc.am.kd.a(Unknown Source) at com.ibm.db2.jcc.am.kd.a(Unknown Source) at com.ibm.db2.jcc.am.kd.a(Unknown Source) at com.ibm.db2.jcc.am.fp.c(Unknown Source) at com.ibm.db2.jcc.am.fp.d(Unknown Source) at com.ibm.db2.jcc.am.fp.a(Unknown Source) at com.ibm.db2.jcc.am.gp.a(Unknown Source) at com.ibm.db2.jcc.t4.bb.h(Unknown Source) at com.ibm.db2.jcc.t4.bb.b(Unknown Source) at com.ibm.db2.jcc.t4.p.a(Unknown Source) at com.ibm.db2.jcc.t4.vb.i(Unknown Source) at com.ibm.db2.jcc.am.fp.kb(Unknown Source) at com.ibm.db2.jcc.am.gp.xc(Unknown Source) at com.ibm.db2.jcc.am.gp.b(Unknown Source) at com.ibm.db2.jcc.am.gp.kc(Unknown Source) at com.ibm.db2.jcc.am.gp.executeQuery(Unknown Source) at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:504) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70) ... 66 more {code}
|