title: Handle EntityNotFoundException when saving parent entity with removed child entity from collection
body: <p>My problem is simple, but yet finding the solution has become a rather tedious and difficult task. </p>
  
  <p>I have two hibernate entities,</p>
  
  <ol>
  <li><code>Owner</code></li>
  <li><code>Dog</code></li>
  </ol>
  
  <p>The <code>Owner</code> (or the "parent" entity) has three fields,</p>
  
  <ol>
  <li><code>name</code></li>
  <li><code>address</code></li>
  <li><code>dogs</code> (a collection of <code>Dog</code> entities - <code>OneToMany</code> relationship).</li>
  </ol>
  
  <p>When removing a <code>Dog</code> from the <code>Owner</code>'s collection (both from the object's collection and from the database via the Dog Repository), as well as updating the address of the Owner, and then trying to save the updated object in the database, the following Exception is thrown: </p>
  
  <p><code>javax.persistence.EntityNotFoundException: Unable to find project.pets.entities.Dog with id 10</code></p>
  
  <p>One way of working around the problem is to get the new version of the <code>Owner</code> once the <code>Dog</code> collection is updated, by calling the Owner's <code>Repository</code> with <code>findOne(ownerId)</code>, before updating the owner's address and saving the entity in the database. </p>
  
  <p>But this does not seem like a proper solution.</p>
  
  <p>I ought to mention that there is no caching implemented.</p>
  
  <p>Has anybody come across such a thing and managed to handle it appropriately?</p>
  
  <p>EDIT 1:</p>
  
  <h2>Sample code:</h2>
  
  <h2>Owner:</h2>
  
  <pre><code>@Entity
  @Table(name = "owners")
  public class Owner {
  
  ...
  
  @Column(name = "address")
  private String address;
  
  @OneToMany(fetch = FetchType.EAGER, mappedBy = "owner", 
             cascade = {CascadeType.MERGE, CascadeType.REMOVE})
  private List&lt;Dog&gt; dogs;
  
  ...
  </code></pre>
  
  <h2>==================================================</h2>
  
  <h2>Dog:</h2>
  
  <pre><code>@Entity
  @Table(name = "dogs")
  public class Dog {
  
   ...
  
  @ManyToOne
  @JoinColumn(name = "owner_id")
  private Owner owner;
  
  ...
  </code></pre>
  
  <h2>==================================================</h2>
  
  <h2>Example code:</h2>
  
  <pre><code>Owner owner = ownerRepository.findOne(ownerId);
  Dog firstDog = owner.getDogs().get(0); // getting the first dog of the owner
  
  owner.getDogs().remove(0); // removing from object's collection
  dogRepository.delete(firstDog); // removing from DB
  
  owner.setAddress("new address");
  ownerRepository.save(owner);
  </code></pre>