title: Best practices for OneToMany with Java
body: <p>Short version:</p>
  
  <p>Lets say I have a One to many relation ship, between Parent and Child. Now in the Java code, is the best practice to read the parent object (get it from the database), and apply some method called addChild in it, or I directly create a child and persist it without reading the Parent ?</p>
  
  <p>Long version</p>
  
  <p>Lets say we have this Parent and Child (from <a href="http://en.wikibooks.org/wiki/Java_Persistence/OneToMany" rel="nofollow">http://en.wikibooks.org/wiki/Java_Persistence/OneToMany</a>)</p>
  
  <pre><code>@Entity
  public class Employee {
    @Id
    @Column(name="EMP_ID")
    private long id;
    ...
    @OneToMany(mappedBy="owner")
    private List&lt;Phone&gt; phones;
    ...
  }
  
  
  @Entity
  public class Phone {
    @Id
    private long id;
    ...
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="OWNER_ID")
    private Employee owner;
    ...
  }
  </code></pre>
  
  <p>And now consider I have a web page where employee can add a phone number. So I already have the id of the parent Employee but I don't have the complete Employee object. </p>
  
  <p>1- I get the whole Employee object from the database (by JPA mapping of course). Then I apply the method employee.addPhone(Phone phone) or something like that. This leads to two queries.</p>
  
  <p>2- I create the phone object, and a wrong employee object that contains only the id of the employee and I persist ?</p>
  
  <p>What are the best practices for this ?</p>