title: orphanRemoval not working properly in hibernate : Element inserted and removed from list is persisted in DB
body: <p>We have an issue that sound like a bug in Hibernate dealing with <strong>orphanRemoval</strong>=<strong>true</strong> for a <strong>oneToMany</strong> <strong>List</strong> (with index).</p>
  
  <p>Here is the simplified mapping :</p>
  
  <pre><code>public class ParentClass {
  
    [...]
  
    @OneToMany(cascade = ALL, mappedBy = "parent", orphanRemoval = true)
    @OnDelete(action = OnDeleteAction.CASCADE)
    @Fetch(FetchMode.JOIN)
    @OrderColumn(name = "pos", nullable = false)
    public List&lt;ChildClass&gt; getChildren() {
      return children;
    }
  
  }
  </code></pre>
  
  <p>And the child class :</p>
  
  <pre><code>public class ChildClass {
      [...]
  
      @ManyToOne
      @JoinColumn(nullable = false, name = "parent_id")
      public ParentClass getParent() {
          return parent;
      } 
  }
  </code></pre>
  
  <p>Given this mapping, the following scenario is failing :</p>
  
  <ol>
  <li>Fetch a <em>Parent</em> from DB</li>
  <li>Add a child to it</li>
  <li>Get something else from DB (not same entity), producing a partial flush</li>
  <li>Remove the child from the parent</li>
  <li>Leave the transaction</li>
  </ol>
  
  <p>Here is the code</p>
  
  <pre><code>@Transactional
  public void test() {
  
    // 1)
    ParentClass parent = entityManager.find(ParentClass.class, "some-id");
  
    // 2)
    ChildClass child = new ChildClass(parent);
    parent.getChildren().add(child);
  
    // 3)
    entityManager.find(SomethingElse.class, "2");
  
    // 4)
    parent.getChildren().remove(child);  
  }
  </code></pre>
  
  <p>In that case, the child allocation is inserted into DB and not removed at te end of the transaction.</p>
  
  <p>However, if we don't do step 3), the child allocation is correctly not persisted in DB</p>
  
  <p>Is that a bug ? A wrong mapping ?
  Is there a workaround for it ?</p>