Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-18-2020 10:42 AM
Hi,
I am using Spring data neo4j (version 5.1.9.Release) and spring-data-commons (2.1.9.Release).
In order to paginate my results, I am using Page
Page<Part> fetchPartsById(@Param("Id") String Id, Pageable pageable);
I call the method fetchPartsById
as follows -
Page<Part> results = fetchPartsById("1", PageRequest(0, 5))
I was expecting that as I am passing size of 5, results.getContent()
should return a list of only 5 elements. However, the list contains all the 40 elements. This defeats the purpose of pagination.
I also tried using Slice
instead of Part
Slice<Part> fetchPartsById(@Param("Id") String Id, Pageable pageable);
Slice<Part> results = fetchPartsById("1", PageRequest(0, 5))
Slice does return only the requested 5 elements. However, the problem with using Slice
is that I am not aware how to get the next set of results. I tried using results.nextPageable()
. This causes the page number to go to next page however it returns no result the second time around. Looks like the results are only on page number 0.
Does anybody know how to use Pagination with Spring data neo4j.
Note : These results are fed to an UI. Hence, the parameters to the PageRequest.of()
are driven by the UI. I want to load initial 5 elements from db and on next request next 5 should be loaded.
Regards,
V
01-18-2020 12:38 PM
We've been using @Query
with these two attributes:
@Query(value="cypherQuery", countQuery="cypherQueryReturnCount")
Page<Part> fetchPartsById(@Param("Id") String Id, Pageable pageable);
We use the regular Neo4jRepository and @Neo4jRepository OGM configurations. I've thought about passing in the SKIP and LIMIT Cypher words into the value query to further optimize the query so OGM has to do less work.
01-18-2020 12:43 PM
Thanks for your reply @mike.blum_neo4j. I have already that on the top of my query in the repository. I just did not show that in the question for brevity. My issue is not that I am not getting results, its that Page
is returning all the elements inside content list and is ignoring the size parameter that I am passing.
01-19-2020 11:51 PM
Apparently findAllById
doesn't support paged querying. I have added this https://jira.spring.io/browse/DATAGRAPH-1286 and will investigate.
01-20-2020 12:26 AM
Thanks for reporting this, @varun85.jobs. There's sadly a ton of stuff going wrong in SDN.
01-20-2020 01:29 AM
One last reply:
findAllById(Iterable<ID> ids, PageRequest)
feels a bit strange: You have a list of ids and you want to create pages from it. Why not just slicing the ids?findAllByIdsIn(Iterable<ID>, PageRequest)
. That will work BUT has a bug with native ids. I'm working on fixing the later.02-02-2020 05:16 AM
Thanks for your reponse @michael.simons1. I think you hit the nail on its head. I was passing in the count query but i was not passing in LIMIT
and SKIP
to the count query. I was just passing it to the actual query.
I got around my issue by using LIMIT
and SKIP
explicitly as I wanted them in the middle of the query and not at the end as added by default when using PagingAndSorting
repository.
All the sessions of the conference are now available online