Pagination and Sorting with Custom Queries


(Mike Blum+Neo4j) #1

Can anyone confirm the state of pagination and sorting in OGM for custom queries these days?

I found this JIRA: https://jira.spring.io/browse/DATAGRAPH-653

but the latest SDN docs say its not supported?

https://neo4j.com/docs/ogm-manual/current/reference/#reference:session:loading-entities:sorting-and-paging

Neo4j OGM does not yet support sorting and paging on custom queries.

My custom repository method looks like this:

  @Query(value = "MATCH (workflow:Workflow {active: TRUE})"
      + "<-[:CONTAINS_WORKFLOW]-(process:Process {active: TRUE}) "
      + "RETURN workflow.id AS id, workflow.name AS name, workflow.objectName AS objectName, "
      + "{id: process.id, name: process.name} AS process ORDER BY workflow.priority ASC;",
      countQuery = "MATCH (workflow:Workflow {active: TRUE})<-[:CONTAINS_WORKFLOW]-(process:Process {active: TRUE}) "
          + "RETURN COUNT(workflow);"
  )
  List<WorkflowResult> findActiveWorkflowsWithProcesses(Pageable pageable);

It sends over this from what the bolt requests are saying:

MATCH (workflow:Workflow {active: TRUE})<-[:CONTAINS_WORKFLOW]-(process:Process {active: TRUE}) RETURN workflow.id AS id, workflow.name AS name, workflow.objectName AS objectName, {id: process.id, name: process.name} AS process ORDER BY workflow.priority ASC with params {0={sort={sorted=false, unsorted=true}, offset=0, pageSize=20, pageNumber=0, unpaged=false, paged=true}}

but the actual response doesn’t seem to respect the pagination.

Should we be manually putting in LIMIT and SKIP into our custom queries?


(Mike Blum+Neo4j) #2

Solution was I need to return Page<WorkflowResult> instead of List<WorkflowResult>


(Gerrit Meier) #3

(Just a note for future users :smiley: )
You are referring to the Neo4j-OGM documentation. The statement is true: No pagination support for custom queries.
You are using SDN and it supports pagination.


(Mike Blum+Neo4j) #4

Ah. That makes sense since OGM really only concerns itself with the POJOs themselves.