hibernate报错a different object with the same identifier value was already associated with the session
来源:互联网 发布:centos源码编译安装 编辑:程序博客网 时间:2024/06/09 23:33
以前也遇到过这个异常,当时也不知道怎么做就上网查,这回又再一次的遇到了这个异常了,决心要追根溯源,找到问题的原点。
a different object with the same identifier value was already associated with the session
这个错误的意思就是2个不同的对象关联到了同一个标志位,也就是说在一个session中存在2个对象,但这 2个对象的标志位是相同的比如2个对象的 id值是一样的 而这又是数据库的唯一主键 ,在做更新操作的时候就出现冲突了,因为Hibernate不知道到底要去更新哪个对象 ,所以就报这个异常了。
在网上搜索给出了这样的几个答案
解决方法一: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里面自带的方法,推荐使用。
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里面自带的方法,推荐使用。
- hibernate报错a different object with the same identifier value was already associated with the session
- 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 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
- 解决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
- 解决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错误
- Qt中所有类型之间的转换
- PHP模拟多进程并发将内容写入文件
- 让win下console支持ls的中文显示
- 浅谈用户名密码登录方式的弊端
- 搜索本地文件夹下文件名
- hibernate报错a different object with the same identifier value was already associated with the session
- ibatis ResultClass和ResultMap的区别
- “天价宣传片”背后果然藏“大鱼”
- cookie详解
- 远程访问MySQL数据库的方法小结
- 旧项目移植至VS2008的编译错误C1189
- svn工作副本不受svn控制导致无法更新
- 0x20FF018B
- 编程思想-正则匹配字符串的一些想法