Search code examples
springneo4jspring-dataspring-data-graph

Paging with Spring Data Graph/Neo4j


Is it possible to fetch Page results when using Spring Data Graph (Neo4J) as the data store?

The findAll(Pageable) seems to be the only Pageable query availalble when using the GraphRepository. What I am looking for is Pageable APIs for other findBy***() like queries.

Perhaps, there may be a completely different (recommended) way to Page results using Spring Data Graph. Thoughts on that are welcome as well!


Solution

  • Spring Data Neo4j (2.0 currently in SNAPSHOT but soon RC1) added Page support for the derived and annotated queries. The findAll() is inherited from CRUD-Repository.

    We could add Page support for the default query methods. Could you raise a JIRA issue for that?

    Example for derived and @Query annotated Page methods.

    interface UserRepository extends GraphRepository<User> {
       // derived method
       Page<User> findByTag(String tag, Pageable page);
       @Query("start user=node({0}) match user-[r:RATED]-product where r.stars > 3 return product order by r.stars desc")
       Page<Product> getRatedProducts(User user);
    }
    

    Just add cypher (or gremlin) as dependency to your application:

    <dependency>
       <groupId>org.neo4j</groupId>
       <artifactId>neo4j-cypher</artifactId>
       <version>${neo4j.version}</version>
    </dependency>