a different object with the same identifier value was already associated with the session
来源:互联网 发布:nginx 常用第三方模块 编辑:程序博客网 时间:2024/05/16 09:22
我遇到的异常:
a different object with the same identifier value was already associated with the session
我的具体问题:我完成了一个修改功能,可是出现如下情况:
1>可以修改,但是修改之后不可以刷新当前页面,否则报上述异常;
2>连续修改,再新增一条数据,上述异常也会出现;
相关知识点:1>hibernate三种状态的区分:瞬时态,持久态和游离态
2>hibernate中merge()和update()方法的区别
我问题的解决:public int updateDepartment(Department department)
{
session.beginTransaction();
session.update(department);----->把update(department)方法改成merge(department)方法就ok了
session.getTransaction().commit();
return 1;
}
关于merge()方法的简介:
merger()方法,很神奇。它可以用来将一个托管(detached)的VO(Value Object)持久化到数据库,以下是它持久化一个托管vo的步骤:
1.在持久化上下文(persist context)中查找与托管VO具有相同ID的PO(persist object),如果找到,就将托管的VO的值copy给PO,然后返回持久化以后的对象;
2.如果在持久化上下文中没有找到,它就会到数据库出找,而且是根据托管的VO提供的ID查找,然后就将托管的VO的值copy给PO,然后返回持久化以后的对象;
3.如果在数据库也没找到和托管的VO对应的记录,它就会要求new一个和托管的VO相对应的持久化对象,然后执行拷贝,返回持久化以后的对象。
注意:如果传给merge()方法的是一个游离态的(transient)对象,那么就会按照第三步执行。
根据对象得id判断,如果是没有保存状态,就做新增;否则,就从数据库装载该对象。
- 解决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错误
- 实现自定义的SWT事件和Listener
- 用Ant实现Java项目的自动构建和部署
- 再YY一下P2P的爬虫吧
- 深度探索Linux内核之离开一个多播组(最简单的情况)
- 坑爹的getHibernateTemplate() 为Null
- a different object with the same identifier value was already associated with the session
- AsyncTask的用法
- 技术支持课--项目实训--储蓄综合业务平台--完成--C语言编写
- java.lang.OutOfMemoryError: Java heap space错误及处理办法(收集整理、转)
- 求二叉树中节点的最大距离
- 我的emacs配置文件
- JS 内部调用函数 的书写方式
- 深度探索Linux内核之加入一个多播组(最简单的情况)
- hub_thread() -- Hub线程