I have a Spring Data Repository interface that gets a collection of nodes from by database using a custom query:
Repository Method:
@Query ("START r = node({0}) MATCH r <-[:AUTHOR]- m RETURN m")
public Page<Object> findObjectById (long objectId,Pageable pageable);
Method call
custRepository.findObjectById (4,new PageRequest(0, 5));
This return a collection of Objects, however the Page information is incorrect. There is enough data in database for me to get several pages of data. The first Page information is saying that there is:
Current Page #: 0
Total Pages: 1
Is First Page: true
Is last Page: true
However when I fetch the second page I am still getting a collection of the other objects and the page information then becomes:
Current Page #: 1
Total Pages: 6
Is First Page: false
Is last Page: false
This clearly show that the page information on the first page is incorrect and since I need accurate information to implement pagination in my app this becomes a problem. What is causing this problem and how do I fix it?
I hand the same problem. Turns out you have to also specify the countQuery attribute of the query annotation. Not sure if its a bug or not so well documented. In your case it should be
@Query (value="START r = node({0}) MATCH r <-[:AUTHOR]- m RETURN m",
countQuery="START r = node({0}) MATCH r <-[:AUTHOR]-m RETURN count(m)")
Hope it helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With