[b]evict方法用于从HibernateSession中移除一个持久化对象。
该对象状态由持久化状态变为游离态。[/b]
在更新的时候调用了saveOrUpdate方法会将一个临时对象持久化,但同事在加日志时要得到修改前对象,所以在我update之前get了一下,此时update报错:a different object with the same identifier value was already associated with the session;
因为get时通过ID将其放入了缓存,saveOrUpdate又要将同一ID对象放入缓存,所以报错。
解决方法:
在get后将得到的对象从缓存中evict。
该对象状态由持久化状态变为游离态。[/b]
在更新的时候调用了saveOrUpdate方法会将一个临时对象持久化,但同事在加日志时要得到修改前对象,所以在我update之前get了一下,此时update报错:a different object with the same identifier value was already associated with the session;
因为get时通过ID将其放入了缓存,saveOrUpdate又要将同一ID对象放入缓存,所以报错。
解决方法:
在get后将得到的对象从缓存中evict。