3

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!

Saket
  • 45,521
  • 12
  • 59
  • 79

1 Answers1

2

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>
Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • Thanks for the details, @Michael. I am good even if the derived methods work - but when I use them, I get an error - "Cypher is not available, please add it to your dependencies". Any ideas why? Meanwhile, I will open the JIRA issue. – Saket Nov 07 '11 at 04:08
  • adding the dependency fixed that error - thanks! But I am now having issues with querying for two properties = getByProperty1AndProperty2() – Saket Nov 09 '11 at 17:40
  • what issues? Please provide some more context. – Michael Hunger Dec 01 '11 at 14:36
  • 2
    To me the handling of paging with @Query annotated parameters is not really clear. Does the example mean that the method is only capable of returning a Page objects or is there also a way to pass a Pageable parameter to the method so I get only the page I want to? – Flo Apr 17 '13 at 13:33