[英]Neo4j OGM 2.0 query path
I am trying to perform a query which returns a path, however, although the same query executed in neo4j Web UI
returns a correct result, the neo4j-ogm
returns null
. 我正在尝试执行一个返回路径的查询,但是,尽管在
neo4j Web UI
执行的同一查询返回了正确的结果,但neo4j-ogm
返回了null
。 I have installed neo4j-ogm-api,core:2.0.0-M01
from Maven. 我已经从Maven安装了
neo4j-ogm-api,core:2.0.0-M01
。
My java code looks as follows: 我的Java代码如下所示:
Root.java: Root.java:
@NodeEntity
public class Root
{
@GraphId
public Long id;
@Relationship(type = "Branch", direction = Relationship.OOUTGOING)
public List<Branch> branches = new ArrayList<>();
public Branch addLeaf(Leaf leaf, float length)
{
Branch b = new Branch(this, leaf);
b.length = length;
leaf.branch = b;
branches.add(b);
return b;
}
}
Leaf.java: Leaf.java:
@NodeEntity
public class Leaf
{
@GraphId
public Long id;
@Property
public String color;
@Relationship(type = "Branch", direction = Relationship.INCOMING)
public Branch branch;
}
Branch.java: Branch.java:
@RelationshipEntity
public class Branch
{
@GraphId
public Long id;
public Branch(Root root, Leaf leaf)
{
this.root = root;
this.leaf = leaf;
}
@Property
public float length;
@StartNode
public Root root;
@EndNode
public Leaf leaf;
}
Then, for testing let's do 然后,进行测试
public class Main {
public static void main(String[] args) {
SessionFactory sessionFactory = new SessionFactory("com.my.package.name");
Session session = sessionFactory.openSession();
Root r = new Root()
r.addLeaf(new Leaf(), 1);
r.addLeaf(new Leaf(), 2);
session.save(r);
//Until this point everything is alright and
// all 3 nodes and 2 relationships are created
String query = "MATCH path = (l1:Leaf)-[*1..100]-(l2:Leaf) WITH path LIMIT 1 RETURN path";
QueryResultModel qrm = session.query(query, new HashMap<String, Object>());
// qrm.result.get(0).get("path") is null
}
}
Please, explain to me what am I doing wrong? 请给我解释我做错了什么?
Returning a full path is not supported. 不支持返回完整路径。 Instead, you need to return the nodes and relationships that you want mapped back to domain entities, such as:
相反,您需要将要映射的节点和关系返回到域实体,例如:
MATCH path = (l1:Leaf)-[*1..100]-(l2:Leaf) WITH path,l1 LIMIT 1 RETURN l1,nodes(path),rels(path)
This will give you an org.neo4j.ogm.session.Result
object. 这将为您提供一个
org.neo4j.ogm.session.Result
对象。 If you retrieve l1 from the underlying Map, you should have a fully hydrated Leaf entity. 如果从基础Map检索l1,则应该具有完全水合的Leaf实体。
BTW not sure what QueryResultModel
is- a QueryResult is only supported in SDN. 顺便说一句,不确定
QueryResultModel
是什么QueryResultModel
仅在SDN中受支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.