SQLCODE=-199, SQLSTATE=42601 error from DB2 12 for paging query in Hibernate

Solution Verified - Updated -

Issue

  • A query for paging is constructed as below

        String jpql = "SELECT e FROM Employee e WHERE SUBSTRING(e.name,3,1) != '-' ORDER BY e.name DESC";
        TypedQuery<Employee> query = entityManager.createQuery(jpql, Employee.class);
        query.setFirstResult(1);
        query.setMaxResults(10);
        for (Employee e : query.getResultList()) {
                log.info("------> Found entity('" + e.getName() + "', '" + e.getTitle() + "')");
        }
    
  • The generated SQL for the query is

        select
            * 
        from
            ( select
                inner2_.*,
                rownumber() over(
            order by
    
            order of inner2_) as rownumber_ from
                ( select
                    employee0_.name as name1_0_,
                    employee0_.title as title2_0_ 
                from
                    Employee employee0_ 
                where
                    substr(employee0_.name, 3, 1)<>'-' 
                order by
                    employee0_.name DESC fetch first 11 rows only ) as inner2_ ) as inner1_ 
            where
                rownumber_ > 1 
            order by
                rownumber_{code}
    
  • The query works with DB2 11 but fails with DB2 12 on Z/OS (with SQLCODE=-199, SQLSTATE=42601).

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7
  • Hibernate 5
  • DB2 12 on Z/OS

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content