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.
What the problem:
//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!
If comment string 1, all works fine!
Exception:
IllegalStateException: Error occurred while storing entity #4700 An entity copy #4700 was already assigned to a different entity @2e7b134a
Questions:
- What is wrong in my sitation?
- As I understand, merge() operation was implemented for those cases, when we alreadty have the entity copy in cache. Am I wrong?
PS
- If it is important Entity -> EntityDetail are linked with lazy, orphanRemoval = true, one-2-one relationship
- I overrided equals() and hashCode() methods.