Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data Neo4j Pageable

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?

like image 460
user2054833 Avatar asked Aug 13 '26 04:08

user2054833


1 Answers

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.

like image 180
PhilBa Avatar answered Aug 14 '26 17:08

PhilBa