title: Play framework JPA: how to implement one-to-many relationship?
body: <p>I have a <code>Posts</code> model and every post also contains <code>Blocks</code> (also a model). I'm using the play framework for this website, and what I want to do is show X number of post with all of it's blocks on one page. JPA (or play framework's implementation, don't know which one it is) has the <code>find()</code> method with which I could query for posts in my controller, and than I would send the post list to my view like this:</p>
  
  <pre><code>render(postList);
  </code></pre>
  
  <p>What I wanted to know is what would be the best way to send the blocks for each post to the view. I could add a <code>getBlocks()</code> method to my Post model, which sends back a blocksList, and call it from the view, but this seems messy to me, and it would defeat the purpose of MVC since the blocks would be fetched from the view.. (or am I wrong about this?)</p>
  
  <p>Does JPA or Play! offer some way of retrieving the blocks together with the posts?</p>
  
  <p>This is what my Post model looks like right now, without getters and setters:@Entity</p>
  
  <pre><code>@Table(name="posts")
  public class Post extends GenericModel{
  
      @Id
      @Column(name="post_id")
      private int id;
  
      @Column(name="post_situation")
      private String situation;
  
      @Column(name="post_date")
      private Date date;
  
      @Column(name="post_userid")
      private int userid;
  
      private List&lt;Block&gt; blockList;
      public List&lt;Block&gt; getBlocks() {
          List&lt;Block&gt; block = null;
          return blockList;
      }
  
  }
  </code></pre>
  
  <p>How should I do this?</p>