问题描述
我在使用Oracle9iDialect进行分页时发现在页面超过20页有时候出现每一页显示和前一页内容一样,后来发现数据库用的是11g而hibernate方言用的是Oracle9iDialect,把Oracle9iDialect换成OracleDialect就没有问题了,求解
解决方案
分页sql是通过dialect生成的OracleDialectpublic 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();}Oracle9iDialectpublic 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();}唯一不同点:if (hasOffset) {pagingSelect.append(" ) row_ ) where rownum_ <= ? and rownum_ > ?");}红色部分 9i不带
解决方案二:
这都找出来了 nb