title: One-To-Many Relationship in Spring Data JPA
body: <p>I would like to have a One-to-many relationship between 2 Entities, Consumer and Policy. One consumer should have several policies.</p>
  
  <p>This is an example of a Consumer JSON object I would like to have:</p>
  
  <pre><code>{
       id : 1,
       name : "Peter",
       endpoint: "123.456.778",
       policies: [
                      {
                         id : 1,
                         name: "policy 01"
                      },
                      {
                         id : 2,
                         name: "policy 02"
                      }
               ]
  }
  </code></pre>
  
  <p>This is what I have so far:</p>
  
  <p><strong>Policy Entity</strong></p>
  
  <pre><code>@Entity
  public class Policy {
          @Id
          @GeneratedValue
          @Column(name = "id")
          private Integer id;
  
          @Column(name = "name")
          private String name;
  
          //getters and setters
      }
  </code></pre>
  
  <p><strong>Consumer Entity</strong></p>
  
  <pre><code>@Entity
  public class Consumer {
  
      @Id
      @GeneratedValue
      @Column(name = "consumer_id")
      private Integer id;
  
      @Column(name = "name")
      private String name;
  
      @Column(name = "endpoint")
      private String endpoint;
  
      @OneToMany
      @JoinColumn(??)
      private List&lt;Policy&gt; policies;
  
    //getters and setters
  }
  </code></pre>
  
  <p>It's not that hard I think, but im trying now for several hours and can't get it done. I'm new to Spring, so if someone is able to help me, I would be very thankfull!</p>