错误:a different object with the same identifier value was already associated with the session
来源:互联网 发布:信息清理软件 编辑:程序博客网 时间:2024/06/15 12:47
好像这个问题经常出现,解决办法也很多,我只推荐一种:
把session.update(object)换成session.merge(object)
这个方法会把object属性拷贝一份存过去,所以就不存在“a different object”这种问题了
代码如下:
public void update(Project p) {Session session = HibernateUtils.getSession();session.merge(p);}
具体用法与原理介绍参见:
Hibernate三种状态的区分,以及save,update,saveOrUpdate,merge等的使用
这篇文章介绍了hibernate的对象的3种状态,分别为:瞬时态(Transient)、 持久态(Persistent)、脱管态(Detached)。处于持久态的对象也称为PO(Persistence Object),瞬时对象和脱管对象也称为VO(Value Object)。然后详细介绍了这几种方法的作用原理与相互之间的区别。
0 0
- 解决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错误
- 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错误
- struts
- hive参数调优汇总
- Git preview代码更新软件学习
- Generator 函数的含义与用法
- 内容提供者ContentProvider的基本使用
- 错误:a different object with the same identifier value was already associated with the session
- 关于网页头部的一些问题
- [搜索]广搜的两道题
- oracle 分组函数rank() over(),dense_rank(),row_number()
- linux下python的调试
- 自定义控件之绘图篇(二):路径及文字
- 一文告诉你机器学习中进行模型评价、模型选择和算法选择的终极方法(PART I)
- 学python的那些事——初学python之菜鸟的起航
- Android 沉浸式状态栏攻略 让你的状态栏变色吧