【问题标题】:IllegalStateException: Error occurred while storing entity <entity> An entity copy <entity> was already assigned to a different entity <entity_copy>IllegalStateException:存储实体 <entity> 时发生错误实体副本 <entity> 已分配给不同的实体 <entity_copy>
【发布时间】: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

问题:

  1. 我的位置有什么问题?
  2. 据我了解,merge() 操作是针对这些情况实施的,当时我们已经在缓存中拥有实体副本。 我错了吗?

附言

  1. 如果很重要 Entity -> EntityDetaillazy, orphanRemoval = true, one-2-one 关系链接
  2. 我重写了 equals() 和 hashCode() 方法。

【问题讨论】:

    标签: hibernate persistence


    【解决方案1】:

    我用下一个方法解决了这个问题:有必要在对它进行一些更改之前合并反序列化的实体。 (唯一的变化是在 2 字符串中):

    //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 = (Entity) session.merge(entityCopy); //2
    entityCopy.setEntityDetail(newDetail); 
    session2.merge(entityCopy); //all works fine
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      • 2013-01-09
      • 2013-10-08
      • 1970-01-01
      相关资源
      最近更新 更多