【发布时间】:2013-08-09 12:48:24
【问题描述】:
经过大量谷歌搜索后,除了降级休眠版本外,我没有找到问题的答案。但是我在 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() 操作是针对这些情况实施的,当时我们已经在缓存中拥有实体副本。 我错了吗?
附言
- 如果很重要 Entity -> EntityDetail 与 lazy, orphanRemoval = true, one-2-one 关系链接
- 我重写了 equals() 和 hashCode() 方法。
【问题讨论】:
标签: hibernate persistence