session.createSQLQuery(sql).setFirstResult(start).setMaxResults(limit).list();
Cannot use 'first', 'limit' or 'skip' in this context
难道hibernate不支持没有映射表的分页查询吗?

解决方案 »

  1.   

    是的,条件比较多而且是多表联合查询
    用的union all
      

  2.   

    建议你用hibernateTemplate.execute(new HibernateCallback(){}用一个回调函数。这样就不会有问题。不知lz是否用过。。
      

  3.   

    把分页的语句也写到sql里面去 可以吧
      

  4.   

    public List<T> query(final int first, final int max, final String hql,final Object[] params) throws BaseDaoException{
    return (List<T>) this.getHibernateTemplate().execute(
    new HibernateCallback() {
    public Object doInHibernate(Session session)
    throws HibernateException {
    Query queryObject = session.createQuery(hql);
    if (params != null && params.length!=0 ) {
    for (int i = 0; i < params.length; i++) {
    queryObject.setParameter(i, params[i]);
    }
    }
    if (first > 0) {
    queryObject.setFirstResult(first);
    }
    if (max > 0) {
    queryObject.setMaxResults(max);
    }
    return queryObject.list();
    }
    }); }
      

  5.   

    1.晒下sql语句
    2.可能是sql的问题,看下下面的解释。-944    Cannot use "first", "limit" or "skip" in this context.This statement uses FIRST N , LIMIT N or SKIP M inside a subquery. This action is not supported.Review the use of FIRST N and check that it is applied only to the outer main
    query SELECT clause. 
      

  6.   

    原因找到了,informix版本太低,不支持联合分页查询
    谢谢各位的解答