hibernate在saveOrUpdate时,update报错:a different object with the same identifier value was already assoc
来源:互联网 发布:中小学生一起作业软件 编辑:程序博客网 时间:2024/06/05 18:32
1 原因:网上说是,在hibernate中同一个session里面有了两个相同标识但是是不同实体。
2 我找出的解决方法是:
getSession().clear(); //在dao层把session清理一下
3 网上查找出还有其他解决方法,其中 getSession().merge(arg0) ;是最有效果的,但是我使用没有解决。具体解释如下,留作以后问题的解决方案:
解决方法一:session.clean() PS:如果在clean操作后面又进行了saveOrUpdate(object)等改变数据状态的操作,有可能会报出"Found two representations of same collection"异常。 解决方法二:session.refresh(object) PS:当object不是数据库中已有数据的对象的时候,不能使用session.refresh(object)因为该方法是从hibernate的session中去重新取object,如果session中没有这个对象,则会报错所以当你使用saveOrUpdate(object)之前还需要判断一下。 解决方法三:session.merge(object) PS:Hibernate里面自带的方法,推荐使用。2、Found two representations of same collection 错误原因:见1。 解决方法:session.merge(object)以上两中异常经常出现在一对多映射和多对多映射中
阅读全文
0 0
- hibernate在saveOrUpdate时,update报错:a different object with the same identifier value was already assoc
- org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already assoc
- hibernate报错a different object with the same identifier value was already associated with the session
- hibernate保存报错:a different object with the same identifier value was already associated with the ses
- Hibernate报错解决 a different object with the same identifier value was already associated with the sess
- spring(错误三) 报错" a different object with the same identifier value was already associated ..."
- a different object with the same identifier value was already (用hibernate的update方法一次请求多次update时出现的错)
- Hibernate Exception: a different object with the same identifier value was already associated with the session
- Hibernate更新a different object with the same identifier value was already associated with the session
- [Hibernate]a different object with the same identifier value was already associated with the session
- Hibernate异常: a different object with the same identifier value was already associated with the sessi
- Hibernate错误:a different object with the same identifier value was already associated with the sessio
- Hibernate:a different object with the same identifier value was already associated with the session
- hibernate a different object with the same identifier value was already associated with the session
- Hibernate :A different object with the same identifier value was already associated with the session
- hibernate:a different object with the same identifier value was already associated with the session
- Hiberate框架进行更新时,报错 :a different object with the same identifier value was already ..
- hibernate异常:a different object with the same identifier value was already associated
- node.js初体验
- day20-实战3
- 'publishing to tomcatv7.0 Server at localhost...'has encountered a problem的解决方法
- 通过设置chrome浏览器解决跨域问题,在本地进行开发工作
- day21-实战4
- hibernate在saveOrUpdate时,update报错:a different object with the same identifier value was already assoc
- 关于浏览器兼容问题
- day22-实战5
- Vue.nextTick()函数
- CentOS 7 安装composer
- Windows消息机制(MFC)
- eclipse配置maven
- JDK源码——java.util.concurrent(八)
- ”想哭“病毒