hibernate 分页

Hibernate 可以实现分页 查询,例如:

Query q = session.createQuery("from Cat as c");
q.setFirstResult(20000);
q.setMaxResults(100);
List l = q.list();

net.sf.hibernate .loader.Loader 这个类里面:

if (useLimit) sql = dialect.getLimitString(sql);
PreparedStatement st = session.getBatcher().prepareQueryStatement(sql, scrollable);

net.sf.hibernate .dialect.MySQLDialect:MySQL的专用分页 语句

public boolean supportsLimit() {
return true;
}
public String getLimitString(String sql) {
StringBuffer pagingSelect = new StringBuffer(100);
pagingSelect.append(sql);
pagingSelect.append(" limit ?, ?");
return pagingSelect.toString();
}

net.sf.hibernate .dialect.Oracle9Dialect: Oracle采用嵌套3层的查询语句结合rownum来实现分页

public boolean supportsLimit() {
return true;
}

public String getLimitString(String sql) {
StringBuffer pagingSelect = new StringBuffer(100);
pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
pagingSelect.append(sql);
pagingSelect.append(" ) row_ where rownum <= ?) where rownum_ > ?");
return pagingSelect.toString();
}

 

你可能感兴趣的:(oracle,sql,mysql,Hibernate,Flash)