nodeBList; } //node B CLass class NodeB { Long id" /> nodeBList; } //node B CLass class NodeB { Long id" /> nodeBList; } //node B CLass class NodeB { Long id"/>

Always loading certain child object in neo4j

97 views Asked by At
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

There are 1 answers

2
Paulin Amougou On

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