a different object with the same identifier value was already associated with the session
来源:互联网 发布:时时彩源码架设教程 编辑:程序博客网 时间:2024/05/16 11:02
再次遇到a different object with the same identifier value was already associated with the session错误
这错误以前遇到过一次,我是这样解决的:
正常情况一般调用hiberate端方法进行数据库操作时,是直接调用 getHibernateTemplate().update(user);,但在hibernate中同一个session里面有了两个相同标识但是是 不同实体时就会出现如标题的错误,在网上找来如下解决方法,错误是解决了,但不完美:
public void update(User user) {
Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
session.clear();
session.update(user);
}
这 样在session.update(user)后如果还有其他对数据库的save或update并且是在同一个事务中,后面的操作可能就会无效,具体原因 没查出来,可能是getcurrentSession()获取的是“当前”session,调用getcurrentSession()时“当前 ”session被从hibernate中剥离,所以导致了后面的操作无效。
如果是struts+hibernate+spring框架下面有个很简单的方法:直接调用getHibernateTemplate().merge(user)。一切搞定!
- 解决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错误
- HibernateSystemException: 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错误
- DotNetFactory
- 黑马程序员_学习日记74_727ASP.NET(模拟Session、jsValidate异步验证表单、AjaxForm异步提交表单)
- AVR(ATMEGA128)+FM1702+M1卡组建RFID系统
- JSP页面中四种变量的范围
- 用sql实现两行记录合并为一行记录
- a different object with the same identifier value was already associated with the session
- 如何在PB脚本当中获取存储过程的返回值
- 恭喜吴敏霞
- httpd2.4.2安装文档
- CityEngine三维建模几个常见问题解决方法(2)
- Sql Server中使用的RowNumber,以及取表的行号
- 合伙创业你须知的几个雷打不动原则
- VC能否释放EXE或DLL
- 装饰设计模式