2016-10-24 4 views
0

テーブル内に複数のフィールドを持つ検索条件があります。同じhibernate criteriaオブジェクトを使用してResult(setFirstResultおよびsetMaxResult)を取得し、ページネーションをカウントすることは可能ですか?私はページネーションを持つ検索基準の結果セットと、その特定の検索基準の結果の合計数を意味します。結果とカウントがハイバーネーションの検索条件

ステップ:

  1. 私の検索パラメータを指定して基準を作成します。
  2. 最初と最大結果パラメータを設定します。
  3. 行数の投影を作成します。 (これは、私の検索パラメータの合計カウントを返します。私の最初と最大の結果パラメータ内ではありません)。
  4. 現在のページの結果セットを取得します。
  5. 検索条件の合計数を取得します。

答えて

0

シンプルなページネーションはこの

public List<YourEntity> findDeviceTransactions(Integer id) { 
    return session.createCriteria(YourEntity.class) 
      .add(Restrictions.eq("id", id)) // add more Restrictions if you want 
      .setFirstResult(page) 
      .setMaxResults(10) //this can be a constant in your properties 
      .list(); 

}

のように見えるカウントがはい

public int countYourEntityForPagination(Integer id) { 
    return ((Number) session.createCriteria(YourEntity.class) 
      .add(Restrictions.eq("id", id)) // add more Restrictions if you want 
      .setProjection(Projections.rowCount()) 
      .uniqueResult()).intValue(); 
} 
+0

のように見える、私は今のと全く同じでした。私は両方を得るために同じ基準を使用することが可能かどうかを探しています。 – Mohan

関連する問題