SDN 4 Session.query doesn't work for @QueryResult

谁都会走 提交于 2019-12-12 03:37:18

问题


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

}

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

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

I use following method for this purpose:

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

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

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

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

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

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

How to get it working with a @QueryResult type ?


回答1:


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

It is only supported on repository queries.



来源:https://stackoverflow.com/questions/38916323/sdn-4-session-query-doesnt-work-for-queryresult

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!