1

After creating a JPA CriteriaQuery, we need to keep it so that we can refine search later or for pagination. In hibernate, we used DetachedCriteria that is not associated with EntityManager. But JPA CriteriaQuery is created from EntityManager. The implemenation of CriteriaQuery may not be serializable depending on JPA provider. Is there a way to save the CriteriaQuery without EntityManager attached? Thanks.

aurelius
  • 3,946
  • 7
  • 40
  • 73
Dave
  • 487
  • 1
  • 6
  • 19
  • Any one has some thoughts one this? With JPA 2.0, do we need to rebuilt CriteriaQuery every time users click previous/next page? I hope the the CriteriaQuery can be saved and re-used once built. – Dave Jun 13 '14 at 03:16
  • The usual way to work the pagination of a query with criteria is to encapsulate the construction of the query in a method that receives the offset and the limit as parameters. It is not a problem since it is efficient from the point of view of speed and memory. – JLazar0 Aug 04 '20 at 11:46

0 Answers0