【问题标题】:How to get total number of pages in oracle with scrollableresults如何使用可滚动结果获取 oracle 中的总页数
【发布时间】:2017-11-29 20:39:08
【问题描述】:

我正在尝试获取给定查询的行数(以便对某些 ui 页面进行分页)。

我在 oracle 数据库上使用休眠 jpa。我的代码是

TypedQuery<AClass> query = getQuery();
Query hquery = query.unwrap(Query.class);
ScrollableResults resultsCount = hquery.scroll();
resultsCount.last();

int rowCount = resultsCount.getRowNumber() + 1;         
resultsCount.close();

尽管有更多行,但它始终返回值 1。 我一定是犯了一个新手错误。

【问题讨论】:

    标签: java oracle hibernate jpa oracle10g


    【解决方案1】:

    为什么不喜欢

    Query<Long> countQuery = getCurrentSession().createQuery("select count(*) from rows");
    return countQuery.uniqueResult().intValue();
    

    【讨论】:

    • 如果可能,我想使用相同的查询来计算和检索实际数据。
    • 但在这种情况下,您不会从分页中受益,因为您将获取所有数据以获取总计数(而不是 Oracle 使用 count(*),然后在单页一次)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 2015-04-12
    • 2015-03-06
    • 1970-01-01
    相关资源
    最近更新 更多