Skip to content
This repository has been archived by the owner on Feb 27, 2020. It is now read-only.

spring-data-neo4j-rest pagination and sorting with custom @Query? #9

Closed
espiegelberg opened this issue Oct 28, 2015 · 3 comments
Closed

Comments

@espiegelberg
Copy link
Contributor

Are Spring Data Neo4j Rest’s pagination and sorting capabilities compatible with custom repository queries?

Based on what I am seeing I am unsure if A) the functionality is simply not supported or B) there is an issue with either C) Spring Data Rest or D) Spring Data Rest Neo4j.

Removing our project as contributing to the issue, we have been able to reproduce the problem by adding Spring Data Rest to the sdn4-univesrity example project. Our steps to produce the issue are:

  1. Checkout sdn4-university from github
  2. Add the following dependency to sdn4-university’s pom.xml:

org.springframework.data
spring-data-neo4j-rest
3.4.0.RELEASE

  1. Replace the project's StudentRepository with the version attached to this issue
    4)Start a local instance of Neo4j with an empty database
  2. Start sdn4-university by executing a “mvn clean spring-boot:run -Drun.jvmArguments="-Dusername=[username] -Dpassword=[password]” from within the proejct
  3. Populate the database by using a browser to http://localhost:8080/api/reload
  4. Use a browser to hit "http://localhost:8080/students/search/findStudyBuddyStudents_with_paginiation?studentId=24"

You will encounter the following stacktrace:

...
14:14:54.217 [main] INFO school.Application - Started Application in 6.456 seconds (JVM running for 7.116)
14:15:01.209 [qtp865744496-15] INFO school.Application - Initialising session-scoped Session Bean
14:15:01.209 [qtp865744496-15] INFO o.s.d.n.config.Neo4jConfiguration - Initialising Neo4jSession
14:15:01.630 [qtp865744496-15] INFO o.s.d.n.config.Neo4jConfiguration - Intercepted exception
14:15:01.641 [qtp865744496-15] WARN o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Handler execution resulted in exception: Failed to convert from type java.util.LinkedHashSet to type org.springframework.data.domain.Page for value '[Student{id=81, name='Ciara Odom', courses=0, studyBuddies=0}, Student{id=89, name='Graiden Haynes', courses=0, studyBuddies=0}, Student{id=162, name='Vaughan Haynes', courses=0, studyBuddies=0}, Student{id=147, name='Michael Daniels', courses=0, studyBuddies=0}, Student{id=146, name='Darryl Rosario', courses=0, studyBuddies=0}]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.util.LinkedHashSet to type org.springframework.data.domain.Page

...

The error message indicates the Cypher query is correctly executed (you can see the correct results in the log) but that LinkedHashSet can not be converted to Spring Data's Page object.

A few questions:

  1. Are pagination and sorting such as this supported when using a custom @query? If so, can you please provide a working sample? (I am unable to find one in the documentation).
  2. Assuming this functionality is supported, what can we do to help resolve the issue? Does it lie within Spring Data Rest or Spring Data Neo4j Rest?
@espiegelberg
Copy link
Contributor Author

public interface StudentRepository extends GraphRepository {

Page<Student> findByName(@Param("name") String name, Pageable pageable);

@Query("match (s1:Student)-[r:BUDDY]-(sb:StudyBuddy)-[r2:BUDDY]-(s2:Student) where id(s1) = {studentId} return s2")
Set<Student> findStudyBuddyStudents_no_paginiation(@Param("studentId") Long studentId);

@Query("match (s1:Student)-[r:BUDDY]-(sb:StudyBuddy)-[r2:BUDDY]-(s2:Student) where id(s1) = {studentId} return s2 order by s2.name {placeholder} ")
Set<Student> findStudyBuddyStudents_no_paginiation_custom_sort(@Param("studentId") Long studentId, @Param("placeholder") String placeholder);

@Query("match (s1:Student)-[r:BUDDY]-(sb:StudyBuddy)-[r2:BUDDY]-(s2:Student) where id(s1) = {studentId} return s2")
Page<Student> findStudyBuddyStudents_with_paginiation(@Param("studentId") Long studentId, Pageable pageable);

}

@luanne
Copy link
Contributor

luanne commented Oct 29, 2015

@espiegelberg paging, sorting and custom depths are not yet supported on custom queries (@query) or derived finders in SDN. There's a JIRA issue to track this: https://jira.spring.io/browse/DATAGRAPH-653
and the documentation stating that this is not yet supported has already been improved (available in the next release).

@luanne luanne closed this as completed Oct 29, 2015
@vdoan
Copy link

vdoan commented Apr 24, 2018

@luanne maybe I am missing something. Can you direct me to where @Depth is supported for custom queries on paging, sorting. Thanks in advance

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants