title: How to get all node's relationships in neo4j using Java Connector Jar
body: <p>Here's my graph</p>
  
  <p><a href="https://i.stack.imgur.com/PUvVC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PUvVC.png" alt="enter image description here"></a></p>
  
  <p>I'm trying to get the details of the nodes and its relationship in java code and below is my code. I'm able to get the details of the nodes but not the relationships. And the java docs has no information and methods that allow exposing of the relationships. </p>
  
  <p><strong>My Code</strong></p>
  
  <pre><code>import java.util.List;
  import org.neo4j.driver.AuthTokens;
  import org.neo4j.driver.Driver;
  import org.neo4j.driver.GraphDatabase;
  import org.neo4j.driver.Record;
  import org.neo4j.driver.Result;
  import org.neo4j.driver.Session;
  import org.neo4j.driver.Value;
  import org.neo4j.driver.internal.InternalResult;
  
  public class Neo4jTest {
  
      private Driver driver;
  
      public Neo4jTest() {
          loadDriver();
      }
  
      private void loadDriver() {
          driver = GraphDatabase.driver("bolt://localhost:7687", AuthTokens.basic("neo4j", "Test"));
      }
  
      public Result createNodes(String query) {
          try (Session session = driver.session())
          {
              InternalResult result = (InternalResult) session.writeTransaction(tx -&gt; tx.run(query));
              return result;
          }
      }
  
      public List&lt;Record&gt; execute(String query) {
          try (Session session = driver.session())
          {
              Result result = session.run(query);
              return result.list();
          }
      }
  
      public void cleanUp(String object) {
          String cleanUpQuery = "match(n:" + object +") detach delete n";
          execute(cleanUpQuery);
      }
  
      public void printResults(List&lt;Record&gt; results) {
          for (Record record : results) {
              Value rec = record.get("n");
              System.out.print("Record --&gt; [");
              for (String key : rec.keys()) {
                  System.out.print(key + " : " + rec.get(key) + ", ");
              }
              System.out.println("]");
  
              //TODO: Need to get all Relationship of this particular node
          }
      }
  
      public static void main(String[] args) {
  
          String createQuery = "create \n" + 
                  "(a:People {name : \"Vivek\", age : 20}), \n" + 
                  "(b:People {name : \"Abdul\", age : 25}), \n" + 
                  "(c:People {name : \"John\", age : 22}),\n" + 
                  "" +
                  "(a)-[:KNOWS]-&gt;(b),\n" + 
                  "(b)-[:FRIEND_OF]-&gt;(c),\n" + 
                  "(c)-[:KNOWS]-&gt;(a)";
  
          String fetchQuery = "match(n:People) return n";
  
          Neo4jTest obj = new Neo4jTest();
          obj.cleanUp("People");
  
          // Create Nodes
          obj.createNodes(createQuery);
  
          // Fetch Nodes
          List&lt;Record&gt; results = obj.execute(fetchQuery);
  
          // Process Results
          obj.printResults(results);
  
      }
  }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>Record --&gt; [name : "Vivek", age : 20, ]
  Record --&gt; [name : "Abdul", age : 25, ]
  Record --&gt; [name : "John", age : 22, ]
  </code></pre>
  
  <p><strong>JavaDoc Link</strong> -> <a href="https://neo4j.com/docs/api/java-driver/current/" rel="nofollow noreferrer">https://neo4j.com/docs/api/java-driver/current/</a></p>
  
  <p><strong>Relevant Result Objects</strong></p>
  
  <pre><code>org.neo4j.driver.Record;
  org.neo4j.driver.Value;
  </code></pre>
  
  <p><strong>Other Details</strong></p>
  
  <p>Neo4j Community Version - 3.5.14 </p>
  
  <p>Neo4j Java Driver Version - 4.0.0</p>
  
  <p><strong>Update</strong> </p>
  
  <p>(for cybersam answer)</p>
  
  <p>The first query doesn't return the relationship as part of the r variable. 
  <a href="https://i.stack.imgur.com/cyerV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cyerV.png" alt="enter image description here"></a></p>
  
  <p>[Update] And the second query also doesn't return relationship
  <a href="https://i.stack.imgur.com/G9Cf7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G9Cf7.png" alt="enter image description here"></a></p>
  
  <p>Results in the neo4j browser and code are the same. </p>
  
  <p>Output for query</p>
  
  <p>MATCH (n:People) WITH COLLECT(n) AS nodes MATCH (:People)-[r]->(:People) WITH nodes, COLLECT(TYPE(r)) AS rels RETURN nodes, rels</p>
  
  <p><a href="https://i.stack.imgur.com/EzO3T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EzO3T.png" alt="enter image description here"></a></p>
  
  <p>Thanks for any help!</p>