title: JPA/Eclipselink poor performance batch update entity on ManyToOne relationship changes
body: <p>I have problem with batch writing in eclipselink when i update an entity properties which link to other entity.</p>
  
  <p>I have a Cardholder entity with @ManyToOne relationship with Card Entity.</p>
  
  <pre><code>@Entity
  @Table(name = "...")
  @NamedQueries({...})
  public class Cardholder implements Serializable {
    ...
    @JoinColumn(name = "card_number", referencedColumnName = "...")
    @ManyToOne(fetch=FetchType.LAZY)
    private Card card;
  }
  </code></pre>
  
  <p>and a Card with @OneToMany relationship with cardholder</p>
  
  <pre><code>@Entity
  @Table(name = "cms_card")
  @NamedQueries({...})
  public class Card implements Serializable {
      @OneToMany(mappedBy = "card")
      private List&lt;Cardholder&gt; cardholderList;
  }
  </code></pre>
  
  <p>I already have List of child (persisted cardholders). Now i want to add some card to them, 
  so :
  // cardholderList is a managed entity list.</p>
  
  <pre><code>for (Cardholder cardholder : cardholderList) {
    Card newCard = new Card();
    ...
    cardholder.setCard(newCard);
    List&lt;Cardholder&gt; cardCardholders = new ArrayList&lt;Cardholder&gt;();
    cardCardholders.add(cardholder);
    newCard.setCardholderList(cardCardholders);
    cardsToBePersisted.add(newCard);
    ++i;
  }
  </code></pre>
  
  <p>I configured my Persistence.xml to use batch-writing, but performance is horribly slow for +-15000 list update. Now, when i check into generated SQL, i found that Eclipselink is creating one batch for one query, its like :</p>
  
  <pre><code>FINER: Begin batch statements
  FINE: INSERT INTO cms_card (card_number, status, chip_serial_number, dwh_status, valid_until, card_holder_id, file_perso_history_id, feedback_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
  FINE:         bind =&gt; [9030002005890011, ACTIVE, null, false, 2015-12-10, null, 241, null]
  FINER: End Batch Statements
  FINER: Begin batch statements
  FINE: UPDATE cms_cardholder SET card_number = ? WHERE (id = ?)
  FINE:         bind =&gt; [9030002005890011, 176075]
  FINER: End Batch Statements
  FINER: Begin batch statements
  FINE: INSERT INTO cms_card (card_number, status, chip_serial_number, dwh_status, valid_until, card_holder_id, file_perso_history_id, feedback_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
  FINE:         bind =&gt; [9030002005889908, ACTIVE, null, false, 2015-12-10, null, 241, null]
  FINER: End Batch Statements
  </code></pre>
  
  <p>I think this is because i set a new parent property (card) to existing children.</p>
  
  <p>I also try to play with reversing the parent - child relationship (cardholder->card instead of card->cardholder). 
  Batch insert is correct after i reverse the relationship in entity and database, but still Eclipselink would query the database (SELECT * from card where cardholder.id = ?), so for 15000 record i got 15000 select statement. Better than above, but still very very slow.</p>
  
  <p>Is there any mistake i made in setting up batch-writing? 
  Thank you very much.</p>