title: org.hibernate.ObjectNotFoundException:No row with the given identifier exists
body: <p>I have had a problem since Hibernate 4.1.8 resulting in the following exception:</p>
  
  <pre><code>org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [test.hibernate.TestPrepravkaOsobaSAdresou$Uvazek#2]
  </code></pre>
  
  <p>I have a simple OneToMany association between two entities:</p>
  
  <pre><code>@Entity(name = "Ppv")
  @Table(name = "PPV")
  public static class Ppv {
  
    @Id
    Long ppvId;
  
    @OneToMany(fetch = FetchType.EAGER, mappedBy = "ppv")
    Set&lt;Uvazek&gt; uvazeks = new HashSet&lt;Uvazek&gt;(0);
  }
  
  
  @Entity(name = "Uvazek")
  @Table(name = "UVAZEK")
  public static class Uvazek {
  
    @Id
    Long uvazekId;
  
    @ManyToOne
    @JoinColumn(name = "PPV_FXID")
    Ppv ppv;
  
  }
  </code></pre>
  
  <p>and a test case where I have one Ppv and two Uvazek. When I load and detach a Ppv, delete one Uvazek associated with loaded Ppv and merge Ppv I get an exception.</p>
  
  <pre><code>jdbcTemplate.execute("insert into PPV values(1)");
  jdbcTemplate.execute("insert into UVAZEK values(2, 1)");
  jdbcTemplate.execute("insert into UVAZEK values(3, 1)");
  
  Ppv ppv = (Ppv) getSession().get(Ppv.class, 1l);
  getSession().clear();
  
  getSession().delete(getSession().get(Uvazek.class, 2l));
  getSession().flush();
  getSession().merge(ppv);
  getSession().flush();             //Causes the exception
  </code></pre>
  
  <p>During the Ppv merge, Hibernate tries to load the deleted Uvazek. Even though Uvazek is deleted, Hibernate still has information about it in </p>
  
  <pre><code>org.hibernate.collection.internal.AbstractPersistentCollection.storedSnapshot
  </code></pre>
  
  <p>on uvazek's set on the detached Ppv. In a previous version (&lt;4.1.8) this works. In this simple example I can repair it by adding <code>orphanRemoval=true</code> on uvazeks set on Ppv and instead of deleting uvazek remove it from uvazeks set on Ppv.</p>
  
  <p>So my question is: Is this a Hibernate bug or my bad practice?</p>