title: How to get spring neo4j cypher custom query to populate an array of child relationships
body: <p>Built-in queries to Spring Data Neo4j (SDN) return objects populated with depth 1 by default.  This means that "children" (related nodes) of an object returned by a query are populated.  That's good - there are actual objects on the end of references from objects returned by these queries.</p>
  
  <p>Custom queries are depth 0 by default.  This is a hassle.</p>
  
  <p>In <a href="https://stackoverflow.com/a/43472033/554807">this answer</a>, it is described how to get springboot neo4j to populate a related element to the target of a custom query - to achieve an extra one level of depth of results from the query.</p>
  
  <p>I am having trouble with this method when the related elements are in a list:</p>
  
  <pre><code>@NodeEntity
  public class BoardPosition {
  
      @Relationship(type="PARENT", direction = Relationship.INCOMING)
      public List&lt;BoardPosition&gt; children;
  </code></pre>
  
  <p>I have a query returning a target <code>BoardPosition</code> and I need it's children to be populated.</p>
  
  <pre><code>@Query("MATCH (target:BoardPosition) &lt;-[c:PARENT]- (child:BoardPosition) 
         WHERE target.play={Play} 
         RETURN target, c, child")
  BoardPosition findActiveByPlay(@Param("Play") String play);
  </code></pre>
  
  <p>The problem is that the query appears to return one separate result for each child, and those results aren't being used to populate the array of children in the target.</p>
  
  <p>Instead of Spring Neo collating the children into the array on the target, I get "only 1 result expected" error - as if the query is returning multiple results each with one child, rather than one result with the children in it.</p>
  
  <blockquote>
    <p>org.springframework.dao.IncorrectResultSizeDataAccessException:
    Incorrect result size: expected at most 1</p>
  </blockquote>
  
  <p>How can I have a custom query to populate that target's children list?</p>
  
  <p>(Note that the built-in <code>findByPlay(play)</code> does what I want - the built-in queries have a depth of 1 rather than 0, and it returns a target with populated children - but of course I need to make the query a bit more sophisticated than just "by Play"... that's why I need to solve this)</p>
  
  <hr>
  
  <p>Versions:</p>
  
  <p><code>org.springframework.data:spring-data-neo4j:5.1.3.RELEASE</code></p>
  
  <p><code>neo4j 3.5.0</code></p>