总是在neo4j中加载某些子对象 [英] Always loading certain child object in neo4j
问题描述
class Node {
Long id;
String name;
@Relationship(type="NodeToCategory")
Address address;
List<NodeB> nodeBList;
}
//node B CLass
class NodeB {
Long id;
String someOther;
@Relationship(type="NodeToCategory")
Address address;
List<NodeC> nodeCList;
}
class Address {
Long id;
String name;
}
当我在Node
上运行深度为2的查询时,它将返回nodeBList
,但不会返回NodeB的地址.我想确保无论何时有地址对象,无论深度如何,都将始终返回地址.它不应将NodeB
的地址返回为Null
.
When I run a query with depth 2 on the Node
it returns nodeBList
but it does not return addresses of NodeB. I want to make sure whenever there is an address object it will always return address no matter the depth . It should not return Addresses of NodeB
as Null
.
一种方法是先加载所有地址,然后再尝试加载
Node
.我正在努力避免这种情况.是否可以通过neo4jOGM中不知道的任何注释或其他功能来完成此操作?
One way of doing is to load all the address before and then trying to load
Node
. I am trying to avoid that. Is there any way of doing it via any annotations or other features that I do not know of in neo4jOGM ?
推荐答案
您可以通过在cypher
中使用@Query
和pattern
来实现.对于具有一个地址的地址,它还将返回带有address
的NodeB
,而对于没有address
的地址,将返回空地址.
You can achieved it by using @Query
and pattern
in your cypher
. It will also return NodeB
with address
for those with one address and null address for those without address
.
@Query("MATCH (na: Node) " +
"WHERE na.name={0} " +
"WITH na " +
"MATCH p=(na)-[*0..2]->(n) " +
"RETURN p")
public Node getNode(String name);
这篇关于总是在neo4j中加载某些子对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!