Monday, May 29, 2017

ORDER BY with NamedQuery and setFirstResult not working

Leave a Comment

This is the @NamedQuery I am using:

@NamedQuery(name = PolicyCase.FIND_FILTERED,         query = "SELECT pc FROM PolicyCase pc "         + "LEFT JOIN pc.responses r "         + "LEFT JOIN r.validations v "         + "WHERE (:product IS NULL OR pc.requested.product = :product) "         + "AND (:channel IS NULL OR pc.requested.channel = :channel) "         + "AND (:insurer IS NULL OR pc.requested.insurer = :insurer) "         + "AND (:status IS NULL OR pc.status = :status) "         + "AND (:filter IS NULL OR v.description LIKE :filter) "         + "GROUP BY pc.id ORDER BY pc.id") 

And this is the call to the @NamedQuery:

List<PolicyCase> policyCases = em.createNamedQuery(PolicyCase.FIND_FILTERED)         .setParameter("product", product)         .setParameter("insurer", insurer)         .setParameter("channel", enumChannel)         .setParameter("status", status)         .setParameter("filter", filter)         .setFirstResult((page - 1) * size)         .setMaxResults(size)         .getResultList(); 

The first page gives me the ordered results, however on the second page the results are not ordered anymore. What am I doing wrong here?

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment