title: Updating a One-to-Many Field in Hibernate
body: <p>Let's say I have <code>Person</code> and <code>Order</code> entities in a uni-directional, <code>one-to-many</code> relationship.</p>
  
  <p><strong>Person</strong></p>
  
  <pre><code>@Entity
  public class Person {
  
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
  
    @OneToMany(mappedBy = "person")
    Set&lt;Order&gt; orders = new HashSet&lt;Order&gt;();
  
    // other fields, constructor, setters and getters
  
  }
  </code></pre>
  
  <p><strong>Order</strong></p>
  
  <pre><code>@Entity
  public class Order {
  
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
  
    @Column(name = "id")
    Person person;
  
    // other fields, constructor, setters and getters
  }
  </code></pre>
  
  <p>How can I update a <code>Person</code>'s <code>Set&lt;Order&gt;</code> with new <code>Order</code>'s?</p>
  
  <p>Do I need to do something like:</p>
  
  <pre><code>Order o = new Order();
  // ???
  
  person.setOrders(new HashSet&lt;Order&gt;(o));
  </code></pre>
  
  <p>Since <code>Person</code> has a <code>OneToMany</code> relationship with <code>Order</code>'s, I'm not sure how to set a <code>Person</code>'s <code>orders</code>.</p>