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

       当出现a different object with the same identifier value was already associated with the session时,一般是因为在hibernate中同一个session里面有了两个相同标识但是是不同实体。

       有如下几种解决方案:

1)使用session.clean(),如果在clean操作后面又进行了saveOrUpdate(object)等改变数据状态的操作,有可能会报出"Found two representations of same collection"异常。

2)使用session.refresh(object),当object不是数据库中已有数据的对象的时候,不能使用session.refresh(object)因为该方法是从hibernatesession中去重新取object,如果session中没有这个对象,则会报错所以当你使用saveOrUpdate(object)之前还需要判断一下。

3session.merge(object)Hibernate里面自带的方法,推荐使用。

 

 

 

更多请参考

http://www.blogjava.net/amigoxie/archive/2008/01/07/173342.html

相关文章:

  • 2021-11-05
  • 2022-12-23
  • 2021-12-13
  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-11
  • 2021-12-17
  • 2021-08-29
  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
相关资源
相似解决方案