问题
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;
}
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
.
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 ?
回答1:
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);
来源:https://stackoverflow.com/questions/49814386/always-loading-certain-child-object-in-neo4j