title: spring-data-neo4j basic one-to-many relationship not persisting
body: <blockquote>
    <p><strong>EDIT</strong>: Sample project available on <a href="https://github.com/troig/neo4jCustomRepository" rel="nofollow">github</a>.</p>
  </blockquote>
  
  <p>I'm using Neo4J (Rest graph database, hosted in grapheneDb) and Spring Data in our backend project. </p>
  
  <pre><code>&lt;bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringCypherRestGraphDatabase"&gt;
  </code></pre>
  
  <p>I have a simple one-to-many relationship between two entities: <code>User</code> and <code>Stay</code>.</p>
  
  <p><strong>EDIT</strong>: I thought this wasn't relevant for the issue, but after seeing a <a href="https://jira.spring.io/browse/DATAGRAPH-735" rel="nofollow">similar problem</a> in SDN4, I think I need to update the question (there is a basic <code>@NodeEntity</code> class, and both entities are extending this base class).</p>
  
  <pre><code>@NodeEntity
  public abstract class BasicNodeEntity implements Serializable {
  
     @GraphId
     private Long nodeId;
  }
  
  
  public class User extends BasicNodeEntity {
  
    @RelatedTo(type = "HAS_STAY",  direction = Direction.OUTGOING)
    Set&lt;Stay&gt; stays;
  
    public void addStay(Stay stay) {
       stays.add(stay);
    }
  }
  
  public class Stay extends BasicNodeEntity {
  
     @RelatedTo(type = "HAS_STAY", direction = Direction.INCOMING)
     User user;
  }
  </code></pre>
  
  <p>I'm unable to persist more than one stay. The first stay I add to the user is persisted correctly, but just the first one. The next stays added never persists, and I always retrieve the first one.</p>
  
  <p>The method I use to create a new stay is:</p>
  
  <pre><code>   @Autowired
     Neo4jOperations template;
  
     @Transactional
     private void createStay(Stay stay, User user) throws Exception {
        stay = template.save(stay);
        user.addStay(stay);
        template.save(user);
        // If i evaluate user at this point, it contains both stays
  
        // But if I retrieve the user from the repository, it just contains
        // the first stay, the second one has not persisted.
     }
  </code></pre>
  
  <p><strong>EDIT</strong>: User modified is retrieved correctly through <code>UserRepository</code>.</p>
  
  <pre><code>public interface UserRepositoryCustom {}
  
  public interface UserRepository extends GraphRepository&lt;User&gt;, UserRepositoryCustom {    
     User findById(String id);
  }
  
  User user = userRepository.findById(userId);
  </code></pre>
  
  <p><em>NOTE: I also tried to save through the repository interface instead of the Neo4jTemplate one, but I have the same problem.</em></p>
  
  <p>Both entities are correctly saved in the neo4j database, it's just a persistence issue.</p>
  
  <p>I think this should be quite easy, so I'm probably missing something..</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Relevant versions:</p>
  
  <pre><code>&lt;spring.version&gt;4.0.5.RELEASE&lt;/spring.version&gt;
  &lt;spring-data-neo4j.version&gt;3.3.2.RELEASE&lt;/spring-data-neo4j.version&gt;
  </code></pre>
  
  <p>There is another <a href="https://stackoverflow.com/questions/29044335/spring-data-neo4j-template-fetch-not-returning-entire-collection">SO question</a> with a very similar problem, but without response so far.</p>