不能对SpringDataNeo4j 4.2 M1(Ingalls)进行排序和分页

时间:2016-11-17 15:01:48

标签: neo4j spring-data-neo4j spring-data-neo4j-4 neo4j-ogm

我需要对SDN 4中的一些自定义查询进行分页和排序。我将SDN升级到最新版本:版本4.2 M1(Ingalls)并基于此ticket此问题在此版本中得到修复。但是,当我尝试进行任何排序或分页时,它会抛出异常说:

org.neo4j.ogm.exception.CypherException: Error executing Cypher; Code: N/A; Description: Unable to convert org.springframework.data.domain.PageRequest to Neo4j Value.

这是我使用的代码:

   Pageable pageable = new PageRequest(0, 3, Sort.Direction.DESC, "name");

   owners = ownerRepository.getOwnersByFacetGroupId(facetGroupId, pageable);

这是我的存储库查询:

public interface OwnerRepository extends Neo4jRepository<Owner> {


@Query("MATCH (n:OWNER)-[r:HAS]-(c:FACET_GROUP) Where id(c)={0} RETURN n")
List<Owner> getOwnersByFacetGroupId(Long id , Pageable pageable);}

这是neo4j使用的最终请求:

Request: MATCH (n:OWNER)-[r:HAS]-(c:FACET_GROUP) Where id(c)={0} RETURN n ORDER BY n.name DESC with params {0=9275402, 1={sort=[{direction=DESC, property=n.name, ignoreCase=false, nullHandling=NATIVE, ascending=false}], offset=0, pageSize=3, pageNumber=0}}

为了能够使用排序和分页,还有什么我必须改变的吗?您能为新实施提供任何示例吗?

这是导致异常的类:org.neo4j.driver.v1.Values

enter image description here 正如您所看到的,if / else子句中不支持PageRequest对象...我正在使用'org.neo4j.driver',名称:'neo4j-java-driver',版本:'1.1.0-M06'。 ......(最新版本)

我为SDN https://repo.spring.io/libs-snapshot/org/springframework/data/spring-data-neo4j/4.2.0.M1/尝试了两个快照/公共广告罐 和 https://mvnrepository.com/artifact/org.springframework.data/spring-data-neo4j/4.2.0.M1

1 个答案:

答案 0 :(得分:3)

感谢SDN活跃社区&amp; Jasper Blues,问题解决了。这些是要遵循的步骤:

1)确保使用springDataNeo4j =&#34; 4.2.0.BUILD-SNAPSHOT&#34;和&#34; neo_ogm =&#34; 2.1.0-SNAPSHOT&#34;依赖。从以下存储库中获取:     maven {url&#39; https://repo.spring.io/libs-snapshot&#39;}     maven {url&#39; http://m2.neo4j.org/content/repositories/snapshots&#39;}

2)不要将@ EnableNeo4jRepositories更改为@ EnableExperimentalNeo4jRepositories和GraphRepository到Neo4jRepository ......这些更改不包含在此快照构建中。

3)要获取可分页的排序结果,请使用此代码作为示例:

 Pageable pageable = new PageRequest(0, 3, Sort.Direction.DESC, "name");
  Page<Owner> owners = ownerRepository.executeMyQuery(pageable);

一切都按预期工作!谢谢大家!!!