title: Hibernate OneToMany mappedby inserts duplicate records when saved
body: <p>I have a simple oneToMany relationship provided in Parent and corresponding ManyToOne in the Chile Entity class:</p>
  
  <p>Parent: </p>
  
  <pre><code>@Entity
  @Table(name = "FormExtraInfo")
  @PrimaryKeyJoinColumn(name="form_container_id")
  public class Form extends Container {
  
  private List&lt;Reason&gt; reasons = new ArrayList&lt;Reason&gt;();
  
  @OneToMany(mappedBy="form",cascade={javax.persistence.CascadeType.ALL},orphanRemoval=true)
  @Cascade(value={CascadeType.ALL})
  public List&lt;Reason&gt; getReasons() {
      return reasons;
  }
  
  public void setReasons(List&lt;Reason&gt; reasons) {
      this.reasons = reasons;
  }
  
  public void addReason(Reason reason) {
      if (this.reasons == null) {
          this.reasons = new ArrayList&lt;Reason&gt;();
      }
  
      this.reasons.add(reason);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Child class:</p>
  
  <pre><code>@ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name="Container_id")
  public Form getForm() {
      return form;
  }
  
  public void setForm(Form form) {
      this.form = form;
  }
  </code></pre>
  
  <p>Action class:</p>
  
  <pre><code>//Set the reasons
      String[] reasonStatus = strutsForm.getMultiValueProperty(REASON_STATUS);
      String[] reasonText = strutsForm.getMultiValueProperty(REASON_TEXT);
  
      List&lt;Reason&gt; reasons = new ArrayList&lt;Reason&gt;();     
  
      logger.debug("form container ID : " + form.getId() +". # of Reasons for this form: "+ reasonText.length);
  
      for (int i = 0; i &lt; reasonText.length; i++) {
          Reason r = new Reason();
          r.setComment(reasonText[i]);
          r.setStatusTypeCode(reasonStatus[i]);
          r.setForm(form); 
          reasons.add(r);
      }
      form.setReasons(reasons);
  </code></pre>
  
  <p>Example case:
  Status_code   Reason_text
  abc           abc1
  xyz           xyz1</p>
  
  <p>save the form:
  Status_code   Reason_text
  abc           abc1
  xyz           xyz1
  abc           abc1
  xyz           xyz1</p>
  
  <p>With any operation : New insert or delete or update, it first duplicates the old data to the DB and then the operation that I performed.</p>