Pagination and Sorting with Custom Queries

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

I found this JIRA: Support paging and sorting for custom queries [DATAGRAPH-653] · Issue #1219 · spring-projects/spring-data-neo4j · GitHub

but the latest SDN docs say its not supported?

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?

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

1 Like

(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.

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