title: IllegalStateException: Error occurred while storing entity <entity> An entity copy <entity> was already assigned to a different entity <entity_copy>
body: <p>After a lot of googling I didn't find answer to my question, except downgrade hibernate version. But I faced this situation at similar post dated as 2003 year.</p>
  
  <p><strong>What the problem:</strong></p>
  
  <pre><code>//in the  first session I do
  session1.save(entity);
  session1.getTransaction().commit();
  session1.close();
  
  //in the second session (after client response), I get back the serialized copy of the entity
  entityCopy = deserialize(jsonString);
  entityCopy.setEntityDetail(newDetail); //1
  session2.merge(entityCopy); //EXCEPTION!
  </code></pre>
  
  <p><strong>If comment string 1, all works fine!</strong></p>
  
  <p><strong>Exception:</strong></p>
  
  <p><strong>IllegalStateException</strong>: <em>Error occurred while storing entity #4700 An entity copy #4700 was already assigned to a different entity @2e7b134a</em></p>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li><em>What is wrong in my sitation?</em> </li>
  <li>As I understand, merge() operation was implemented for those cases, when we alreadty have the entity copy in cache. <em>Am I wrong?</em></li>
  </ol>
  
  <p><strong>PS</strong></p>
  
  <ol>
  <li>If it is important <strong>Entity -> EntityDetail</strong> are linked with <strong><em>lazy, orphanRemoval = true, one-2-one</em></strong> relationship</li>
  <li>I overrided equals() and hashCode() methods. </li>
  </ol>