本文介绍了Spring Data Neo4j 4 和 Pageable @QueryResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过 SDN 4 Repository 方法为我的自定义 Cyper 查询引入 Pageable
支持:
I'm trying to introduce Pageable
support for my custom Cyper query over SDN 4 Repository method:
@Query(value = "MATCH (parentD)-[:CONTAINS]->(childD:Decision)-[ru:CREATED_BY]->(u:User) WHERE id(parentD) = {decisionId} OPTIONAL MATCH (childD)<-[:VOTED_FOR]-(vg:VoteGroup)-[:VOTED_ON]->(c:Criterion) WHERE id(c) IN {criteriaIds} WITH childD, ru, u, vg.avgVotesWeight as weight RETURN childD AS decision, ru, u, sum(weight) as weight ORDER BY weight DESC", countQuery="MATCH (parentD)-[:CONTAINS]->(childD:Decision) WHERE id(parentD) = {decisionId} RETURN count(childD)")
Page<WeightedDecision> getChildDecisionsSortedBySumOfCriteriaAvgVotesWeight(@Param("decisionId") Long decisionId, @Param("criteriaIds") Set<Long> criteriaIds, Pageable pageable);
WeightedDecision
是一个 @QueryResult:
WeightedDecision
is a @QueryResult:
@QueryResult
public class WeightedDecision {
private Decision decision;
private double weight;
public Decision getDecision() {
return decision;
}
public void setDecision(Decision decision) {
this.decision = decision;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
}
现在这个逻辑失败,出现一个 ClassCastException
异常:
Right now this logic fails with a ClassCastException
exception:
java.lang.ClassCastException: com.example.domain.model.decision.result.WeightedDecision cannot be cast to org.springframework.data.domain.Page
我做错了什么以及如何解决?
What am I doing wrong and how to fix it ?
推荐答案
SDN 2.0.4 版不支持@QueryResult
s 的分页.2.0.5 版将支持此功能,该功能可用于快照构建存储库中的 UAT.
Version 2.0.4 of SDN did not support paging for @QueryResult
s. Version 2.0.5 will support this, and the feature is available for UAT in the snapshot build repository.
这篇关于Spring Data Neo4j 4 和 Pageable @QueryResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!