spring+hibernate+struts1分页问题

我在使用Oracle9iDialect进行分页时发现在页面超过20页有时候出现每一页显示和前一页内容一样,后来发现数据库用的是11g而hibernate方言用的是Oracle9iDialect,把Oracle9iDialect换成OracleDialect就没有问题了,求解

2个回答

分页sql是通过dialect生成的

OracleDialect
[code="java"] public String getLimitString(String sql, boolean hasOffset) {

    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(sql);
    if (hasOffset) {
        pagingSelect.append(" ) row_ ) where rownum_ <= ? and rownum_ > ?");
    }
    else {
        pagingSelect.append(" ) where rownum <= ?");
    }

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

    return pagingSelect.toString();
}[/code]

Oracle9iDialect
[code="java"] public String getLimitString(String sql, boolean hasOffset) {

    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(sql);
    if (hasOffset) {
        pagingSelect.append(" ) row_ where rownum <= ?) where rownum_ > ?");
    }
    else {
        pagingSelect.append(" ) where rownum <= ?");
    }

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

    return pagingSelect.toString();
}

[/code]

唯一不同点:

    if (hasOffset) {
        pagingSelect.append(" ) row_ [color=red])[/color] where rownum_ <= ? and rownum_ > ?");
    }

红色部分 9i不带

这都找出来了 nb

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!