a different object with the same identifier value was already associated with th

该对象状态由持久化状态变为游离态。

在更新的时候调用了saveOrUpdate方法会将一个临时对象持久化,但同事在加日志时要得到修改前对象,所以在我update之前get了一下,此时update报错:a different object with the same identifier value was already associated with the session;

因为get时通过ID将其放入了缓存,saveOrUpdate又要将同一ID对象放入缓存,所以报错。

解决方法:
    在get后将得到的对象从缓存中evict
方法2:
   使用方法:merge来更新保存对象

你可能感兴趣的:(object)