本文介绍了SDN 4 Session.query不适用于@QueryResult的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的SDN 4项目中,我有一个@QueryResult POJO:

In my SDN 4 project I have a @QueryResult POJO:

@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;
    }

}

许多Spring Data Neo4j存储库方法可以很好地与此WeightedDecision查询结果配合使用.

And a lot of Spring Data Neo4j repository methods that work fine with this WeightedDecision query result.

现在,我正在尝试手动构造一个Cypher查询,并在其中返回结果WeightedDecision的列表.

Right now I'm trying to manually construct a Cypher query where I'm going to return the list of WeightedDecision as a result.

我为此使用以下方法:

return (List<WeightedDecision>) session.query(WeightedDecision.class, cypher, parameters);

我的Cypher查询如下:

my Cypher query looks like:

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

,但是session.query的结果在这种情况下为空.

but the result of session.query is empty in this case.

如果将session.query方法参数更改为:

If I'm changing the session.query method parameters to:

return (List<WeightedDecision>) session.query(Decision.class, cypher, parameters); 

其中Decision是节点实体,一切正常,并返回决策列表.

where Decision is a Node Entity everything works fine and returns List of Decision.

如何使其与@QueryResult类型一起使用?

How to get it working with a @QueryResult type ?

推荐答案

@QueryResult不是OGM概念,因此OGM会话不支持.

@QueryResult is not an OGM concept and hence is not supported by the OGM Session.

它仅在存储库查询中受支持.

It is only supported on repository queries.

这篇关于SDN 4 Session.query不适用于@QueryResult的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 21:41