cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

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

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?

1 ACCEPTED SOLUTION

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

View solution in original post

3 REPLIES 3

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

(Just a note for future users )
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.