a different object with the same identifier value was already associated with异常解决
来源:互联网 发布:mac 微信公众号开发 编辑:程序博客网 时间:2024/05/18 01:25
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">Hibernate框架下实现更新用户信息发生了如下错误:</span>
a different object with the same identifier value was already associated with.....
在网上查阅可资料,发现这种错误通常是由于,数据库中存在着一个持久态的对象,而此时更新数据接收页面传递过来的对象为瞬时态对象,在hibernate中同一个session里面有了两个相同标识但是是不同实体,因此报错,网上参考了其他的解决方法:
(1)使用session.clean(),如果在clean操作后面又进行了saveOrUpdate(object)等改变数据状态的操作,有可能会报出"Found two representations of same collection"异常。(2)使用session.refresh(object),当object不是数据库中已有数据的对象的时候,不能使用session.refresh(object)因为该方法是从hibernate的session中去重新取object,如果session中没有这个对象,则会报错所以当你使用saveOrUpdate(object)之前还需要判断一下。(3)session.merge(object),Hibernate里面自带的方法,推荐使用。最后采取了笨重的方法,利用条件查出来最新的对象,让后通过合并更新后的值插入数据库,这种方法解决了上述冲突问题,虽然还是不太完美,希望大家有更好的方法可以指教。
Userinfo userinfo1 = (Userinfo)session.get(Userinfo.class, userinfo.getUserId());//session.saveOrUpdate(userinfo);//session.flush();//session.refresh(userinfo);userinfo1.setUserName(userinfo.getUserName());userinfo1.setUserPass(userinfo.getUserPass());userinfo1.setUserType(userinfo.getUserType());userinfo1.setUserDepart(userinfo.getUserDepart());userinfo1.setUserEmail(userinfo.getUserEmail());userinfo1.setUserRegtime(userinfo.getUserRegtime());userinfo1.setUserStatus(userinfo.getUserStatus());session.update(userinfo1);
0 0
- a different object with the same identifier value was already associated with异常解决
- Hibernate异常: a different object with the same identifier value was already associated with the sessi
- 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错误
- 解决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错误
- 解决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错误
- 解决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
- 解决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错误
- 解决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错误
- 解决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错误
- 解决 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错误
- ClassTwo项目总结--第一次失败经历
- RHEL7 (134) KickStart
- java事物处理
- RHEL 7 (134) 正则表达式中的GREP
- hiho一下 第四十八周——拓扑排序二
- a different object with the same identifier value was already associated with异常解决
- rhel 7 (134) 计划任务
- RHEL7 (134) 管理进程优先级
- 软件测试二八原则(软测之魂读后感)
- 学院网站设计大赛总结
- RHEL7 (134) SELINUX
- BP算法权重求导
- Weyl不等式
- CAS—注销登录后跳转到登录页