A different object with the same identifier value was already associated with the session错误解决方法
2011-12-08 11:36
441 查看
错误:A different object with the same identifier value was already associated with the session
今天又碰到这个错误,知道是怎么回事但是忘记在哪儿写过改正代码了,为了避免下一次再找不到,就写到这里吧。
这个错误产生的原因是因为在hibernate中同一个session里面有了两个相同标识但是是不同实体.也就是说内存中存在两个id相同的实体造成冲突,(我在修改实体之前又一次查询操作,这时内存中有一个实体,当修改完成保存时又会提交一个相同id的实体,因此就会存在两个标识相同的实体)系统不知道该调用哪一个实体因此而报错。
解决方法:
清理掉内存中已存在的实体即可,相关代码如下:
今天又碰到这个错误,知道是怎么回事但是忘记在哪儿写过改正代码了,为了避免下一次再找不到,就写到这里吧。
这个错误产生的原因是因为在hibernate中同一个session里面有了两个相同标识但是是不同实体.也就是说内存中存在两个id相同的实体造成冲突,(我在修改实体之前又一次查询操作,这时内存中有一个实体,当修改完成保存时又会提交一个相同id的实体,因此就会存在两个标识相同的实体)系统不知道该调用哪一个实体因此而报错。
解决方法:
清理掉内存中已存在的实体即可,相关代码如下:
public voidupdateByMerge(User user) { Session session = getHibernateTemplate().getSessionFactory(). getCurrentSession(); session.clear(); session.update(user); }
相关文章推荐
- 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错误的一种解决方法
- 解决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错误 .
- 解决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 一个经典的hibernate错误
- 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错误
- Nhibernate 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