2

Can someone give an example countQuery to implement pagination while doing explicit query (@Query) using Micronaut data? There is no examples at https://micronaut-projects.github.io/micronaut-data/latest/guide/#explicitQueries

I have to make a query like the one below

@Query("From UserRelation where userId = :userId and itemId=:itemId", countQuery = <count query here>)
Sujith C P
  • 105
  • 1
  • 11

1 Answers1

1

You can do it in this way:

@Query(
  value = "select relation_ from UserRelation relation_ where relation_.userId = :userId and relation_.itemId = :itemId", 
  countQuery = "select count(relation_) from UserRelation relation_ where relation_.userId = :userId and relation_.itemId = :itemId"
)

The count query will be the same only with one change and it is the count() function in the SELECT clause.

cgrim
  • 4,890
  • 1
  • 23
  • 42