title: annotation mapping bidirectional OneToMany/ManyToOne not fetching?
body: <p>I'm clearly struggling to understand this so help greatly appreciated...</p>
  
  <p>I have the following mapping:</p>
  
  <pre><code>@Entity
  @Table(name = "parent")
  public class ParentEntity
  {
  ...
      @Id
      @Column(name = "parent_id")
      private Long id;
  ...
      @OneToMany(mappedBy = "parent", fetch = FetchType.EAGER)
      private List&lt;ChildEntity&gt; children;
  ...
  }
  
  @Entity
  @Table(name = "child")
  public class ChildEntity
  {
  ...
      @Id
      @Column(name = "child_id")
      private Long id;
  ...
      @ManyToOne(fetch = FetchType.EAGER)
      @NotFound(action = NotFoundAction.IGNORE)
      @JoinColumn(name = "parent_id")
      private ParentEntity parent;
  ...
  }
  </code></pre>
  
  <p>in my db i have:</p>
  
  <pre><code>parent
  ------
  parent_id: 1
  
  child
  ------
  child_id: 1, parent_id: 1
  </code></pre>
  
  <p>However</p>
  
  <pre><code>((Parent) session.get(Parent.class, 1)).getChildren()
  </code></pre>
  
  <p>returns null.</p>
  
  <p>can anyone see what I have missing?</p>
  
  <p>thanks, p.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It seems to be more-so to do with session state in that the collection is not populated in the context of the same session, but the collection is populated in the next session...</p>
  
  <p>consider the following:</p>
  
  <pre><code>void setupRender()
  {
      debug("existing not just added", (ParentEntity) session.get(ParentEntity.class, 13L));
  
      ParentEntity parent = new ParentEntity();
      session.save(parent);
  
      ChildEntity child = new ChildEntity();
      child.setParent(parent);
      session.save(child);
  
      debug("new one before commit", parent);
  
      sessionManager.commit();
  
      debug("new one after commit", parent);
  
      debug("new one after re-fetch", (ParentEntity) session.load(ParentEntity.class, parent.getId()));
  }
  
  private void debug(String prefix, ParentEntity parent)
  {
      log.debug(prefix + ": parent id: " + parent.getId() + ", Children is "
              + (parent.getChildren() == null ? "null" : "size:" + parent.getChildren().size()));
  }
  </code></pre>
  
  <p>results in the following output:</p>
  
  <pre><code>DEBUG - existing not just added: parent id: 13, Children is size:1
  DEBUG - new one before commit: parent id: 23, Children is null
  DEBUG - new one after commit: parent id: 23, Children is null
  DEBUG - new one after re-fetch: parent id: 23, Children is null
  </code></pre>
  
  <p>so if it's due to session state, and commit isn't enough to trigger a re-fetch, what do I have to do to get the mapping to fetch the collection?</p>
  
  <p>thanks again!</p>