首页 > 数据库 >Hibernate下分页语句第一页和第二页sql语句不一致问题解决方法

Hibernate下分页语句第一页和第二页sql语句不一致问题解决方法

时间:2023-02-03 09:14:55浏览次数:45  
标签:语句 pagingSelect Hibernate 第二页 select sql rownum append

<prop key="hibernate.dialect">
新增类
OracleDialect
</prop>

OracleDialect  extends org.hibernate.dialect.Oracle10gDialect 
重写 getLimitString方法
        sql = sql.trim();
        boolean isForUpdate = false;
        if (sql.toLowerCase().endsWith(" for update")) {
            sql = sql.substring(0, sql.length() - 11);
            isForUpdate = true;
        }

        StringBuffer pagingSelect = new StringBuffer(sql.length() + 100);
        if (hasOffset) {
            pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
        } else {
            //pagingSelect.append("select * from ( ");
            pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
        }

        pagingSelect.append(sql);
        if (hasOffset) {
            pagingSelect.append(" ) row_ where rownum <= ?) where rownum_ > ?");
        } else {
           // pagingSelect.append(" ) where rownum <= ?");
            pagingSelect.append(" ) row_ where rownum <= ?) where rownum_ > 0");
        }

        if (isForUpdate) {
            pagingSelect.append(" for update");
        }

        return pagingSelect.toString();

  

标签:语句,pagingSelect,Hibernate,第二页,select,sql,rownum,append
From: https://www.cnblogs.com/fengyu9/p/17087968.html

相关文章