title: OpenJPA orphan removal not working
body: <p>I am trying out a master child test case with a OneToMany unidirectional relationship.
  I have a scenario where I want to update the master by removing some entries from the children list. When I do a merge, I want these child entries to be automatically deleted.</p>
  
  <p>I have tried in vain to get this working. I tried orphanremoval too, but that too didn't help. There were some suggestions to add equals and hashcode, which didn't work either.</p>
  
  <p>Any hint or help in this regard is highly appreciated. Thank you.</p>
  
  <p>I am using JPA2.0 with OpenJPA 2.1.0</p>
  
  <p>Here is my code.</p>
  
  <pre><code>//Parent class
  public class Account {
      private String accountId;
      private String accountNumber;
      private List&lt;SubAccount&gt; subAccounts;
  
      //followed by getters/setters 
  }
  
  //Child class
  public class SubAccount {
      private String subAccountId;
      private String subAccountNumber;
      //followed by getters/setters 
  }
  </code></pre>
  
  <p>My orm.xml is as follows.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;entity-mappings version="2.0"
      xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"&gt;
  
      &lt;entity name="Account" class="test.data.Account"&gt;
          &lt;table name="ACCOUNT" /&gt;
  
          &lt;sequence-generator name="AccountSeq"
              sequence-name="ACCOUNT_TEST_SEQ" /&gt;
  
          &lt;attributes&gt;
  
              &lt;id name="accountId"&gt;
                  &lt;column name="ACCOUNT_ID" /&gt;
                  &lt;generated-value strategy="SEQUENCE" generator="AccountSeq" /&gt;
              &lt;/id&gt;
  
              &lt;basic name="accountNumber"&gt;
                  &lt;column name="ACCOUNT_NO" /&gt;
              &lt;/basic&gt;
  
              &lt;one-to-many name="subAccounts" fetch="EAGER"
                  target-entity="test.data.SubAccount" orphan-removal="true" &gt;
                  &lt;join-column name="ACCOUNT_ID" referenced-column-name="ACCOUNT_ID" nullable="false" updatable="true"/&gt;
                  &lt;cascade&gt;
                      &lt;cascade-all /&gt;
                  &lt;/cascade&gt;
              &lt;/one-to-many&gt;
  
          &lt;/attributes&gt;
      &lt;/entity&gt;
  
      &lt;entity name="SubAccount" class="test.data.SubAccount"&gt;
          &lt;table name="SUBACCOUNT" /&gt;
  
          &lt;sequence-generator name="SubAccountSeq"
              sequence-name="SUBACCOUNT_TEST_SEQ" /&gt;
  
          &lt;attributes&gt;
              &lt;id name="subAccountPK"&gt;
                  &lt;column name="SUBACCOUNT_ID" /&gt;
                  &lt;generated-value strategy="SEQUENCE" generator="AccountSeq" /&gt;
              &lt;/id&gt;
              &lt;basic name="subAccountNumber"&gt;
                  &lt;column name="SUBACCOUNT_NO" /&gt;
              &lt;/basic&gt;
          &lt;/attributes&gt;
      &lt;/entity&gt;
  
  &lt;/entity-mappings&gt;
  </code></pre>
  
  <p>And this is what I am trying to do.</p>
  
  <pre><code>Account acc = (Account)entityMgr.find(Account.class, "1100")
  acc.getSubAccounts().remove(0);
  entityMgr.merge(acc)
  </code></pre>
  
  <p>I expect the subaccount to be deleted.</p>