Always loading certain child object in neo4j

好久不见. 提交于 2019-12-11 14:53:15

问题


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

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