多くのグーグル検索の後、休止状態のバージョンをダウングレードすることを除いて、質問に対する答えが見つかりませんでした。しかし、2003年の同様の投稿でこの状況に直面しました。
何の問題:
//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!
コメント文字列 1 の場合、すべて正常に動作します。
例外:
IllegalStateException :エンティティ #4700 の保存中にエラーが発生しました エンティティ コピー #4700 は、別のエンティティ @2e7b134a に既に割り当てられています
質問:
- 私の状況で何が問題になっていますか?
- 私が理解しているように、エンティティのコピーが既にキャッシュにある場合、merge() 操作はそのような場合に実装されました。私が間違っている?
PS
- 重要な場合はEntity -> EntityDetailはlazy、orphanRemoval = true、1 対 1 の関係でリンクされています
- equals() および hashCode() メソッドをオーバーライドしました。