Handling Pageable for UNION query in Spring Boot

How do you handle the UNION query for Pagination in Spring Boot and Neo4j? I'm getting the following error:

Result not of expected size. Expected 1 row but found 2] with root cause
java.lang.RuntimeException: Result not of expected size. Expected 1 row but found 2

The query is ->
</>
@Query("""MATCH (n:NodeA )-[]->(r:NodeB) RETURN r UNION ALL MATCH (r:NodeB) RETURN r""",
countQuery = """MATCH (n:NodeA)-[
]->(r:NodeB) RETURN COUNT(r)UNION ALL MATCH (r:NodeB) RETURN COUNT(r)""")
fun findNodeB(pageable: Pageable): Page

</>

Configurations

  • neo4jVersion = "3.5.+"
  • springDataNeo4jVersion = "5.3.4"
  • language = Kotlin