title: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance
body: <p>In my application, a hibernate operation goes like this.
  The application updates a parent entity with new values from the request and deletes all the existing (previously inserted) child entities and inserts new child records.</p>
  
  <p>I'm using hibernates <code>DELETE_ORPHAN</code> for this, as you can see below.</p>
  
  <p>When i do this, I'm getting the below exception :</p>
  
  <blockquote>
    <p>org.hibernate.HibernateException: A collection with
    cascade="all-delete-orphan" was no longer referenced by the owning
    entity instance: com.childs</p>
  </blockquote>
  
  <p>I saw similar threads with the problem, and I tried to appy solutions in those threads.  But that didn't work</p>
  
  <p>My Parent entity</p>
  
  <pre><code>    public class Parent implements Serializable {
  
              @Column(name = "PARENT_ID")
              @Basic(fetch = FetchType.EAGER)
              @Id
              @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
              @SequenceGenerator(name = "seq", sequenceName = "seq")
              private Integer parentId;  //primary key of parent
  
              ....... 
              ........
  
              //mapping to child entity
              @OneToMany(mappedBy = "parent", cascade = { CascadeType.ALL }, fetch =  FetchType.LAZY)
              @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
              private Set&lt;Child&gt; childs;
  
              ................
              ...............
  
  }
  </code></pre>
  
  <p>Child entity has a combined key and has a PK entity has shown below</p>
  
  <pre><code>public class ChildPK implements Serializable {
  
      /** The Constant serialVersionUID. */
      private static final long serialVersionUID = -447592368963477750L;
  
      /** . */
      @ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
      @JoinColumns( { @JoinColumn(name = "PARENT_ID", referencedColumnName = "PARENT_ID") })
      @Id
      private Parent parent;
  
      /**. */
  
      @Column(name = "CHILD_ID")
      @Basic(fetch = FetchType.EAGER)
      @Id
      @GenericGenerator(name="child_seq",    strategy="com.DB2Dialect") 
      @GeneratedValue(generator="child_seq") 
      private Integer childId;
  
  }
  
  child entity goes like this:
  
  
  public class Child implements Serializable {
  
      /** The Constant serialVersionUID. */
      private static final long serialVersionUID = 185670997643552301L;
  
      /** The pol cntct id. */
      @Column(name = "CHILD_ID")
      @Basic(fetch = FetchType.EAGER)
      @Id
      private Integer childId;
  
      @ManyToOne(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
      @JoinColumns( { @JoinColumn(name = "PARENT_ID", referencedColumnName = "PARENT_ID") })
      @Id
      private Parent parent;
  
  }
  </code></pre>
  
  <p>Java code</p>
  
  <pre><code>   ...................
      ..............
      parent.getChild().clear();
      Child child = new Child(); 
      parent.setChild(child);
  </code></pre>
  
  <p>What could be wrong here.<br>
  Thanks in advance...</p>