title: Neo4j eager/lazy loading with Spring data
body: <p>I'm investigating Neo4j and have a question with regards to object eager/lazy loading. Lets say I have class Trolley with has <code>Set&lt;Item&gt;</code> (with getters/setters). If I do the following:</p>
  
  <pre><code>Trolley t = new Trolley(...); // create empty trolley
  t.addItem(f);  // add one item to the trolley
  t.persist(); // persist the object 
  </code></pre>
  
  <p>I then later find the trolley based on the nodeId:</p>
  
  <pre><code>repo.findOne(xxx); // returns the trolley successfully
  </code></pre>
  
  <p>When I do something like:</p>
  
  <pre><code>trolley.getItems().size() 
  </code></pre>
  
  <p>this is empty. I guess this is the intended behaviour. Is there any mechanism similar to JPA where is the session/tx is open to load the collection dynamically. </p>
  
  <p>Code:</p>
  
  <pre><code>@NodeEntity
  public class Trolley
  {
      @Indexed
      private String name;
  
      @RelatedTo
      private Set&lt;Item&gt; items;
  
      public Trolley(){}
  
      public Trolley(String name)
      {
          this.name = name;
      }
  
      public void addItem(Item item)
      {
          this.items.add(item);
      }
  
      public Set&lt;Item&gt; getItems()
      {
          return items;
      }
  
  }
  
  @NodeEntity
  public class Item
  {
      private String name;
  
      public Item(){}
  
      public Item(String name)
      {
          this.name = name;
      }
  
      public String getName()
      {
          return name;
      }
  }
  
  @Test
  public void trolleyWithItemPersist()
  {
      Trolley trolley = new Trolley("trolley1").persist();
  
      // Persisting - however I would've expected a cascade to
      // occur when adding to the collection.
      Item item =  new Item("item1").persist();
  
      // now add to the trolley
      trolley.addItem(item);
  
      // persist
      trolley.persist();
  
      // Now use repo to get trolley
      Trolley loadedTrolley = trolleyRepository.findOne(trolley.getNodeId());
  
      // should have one item
      assertEquals(1, loadedTrolley.getItems().size());
  
  }
  </code></pre>