当前位置:网站首页>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
2022-07-31 05:08:00 【小果子^_^】
a different object with the same identifier value was already associated with the session
出现这个问题的时候,我首先百度,结果百度了三四个小时都没解决。。。
首先说一下百度的结果:
好多都是写了三种方法而且有错误也会显示错误原因:
错误原因:在hibernate中同一个session里面有了两个相同标识但是是不同实体。
1. session.clean()
如果在clean操作后面又进行了saveOrUpdate(object)等改变数据状态的操作,有可能会报出"Found two representations of same collection"异常
2. session.refresh(object)
当object不是数据库中已有数据的对象的时候,不能使用session.refresh(object)因为该方法是从hibernate的session中去重新取object,如果session中没有这个对象,则会报错所以当你使用saveOrUpdate(object)之前还需要判断一下。
3. session.merge(object)
Hibernate里面自带的方法,推荐使用。
但是这些对我都没用,关键是我也不知道怎么获取这个session。。。
后来冷静想了一下,出现这个问题的原因,的确是我做批量修改之后出现的,但是前提是,我把这个批量修改的方法放在了多线程中,执行到一半,我就重启了服务,后来访问方法,一直报这个问题,我甚至初始化过数据库(这个大家操作的时候,要先备份原来的数据库)都不行,后来突然想到,多线程执行的方法,所以解决方法就是:直接打开任务管理器,直接把java进程都杀死了
最后又重启了一下服务,才得以解决。
边栏推荐
- Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]
- mysql uses on duplicate key update to update data in batches
- centos7安装mysql5.7步骤(图解版)
- Numpy中np.meshgrid的简单用法示例
- Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.
- [R language] [3] apply, tapply, lapply, sapply, mapply and par function related parameters
- DVWA shooting range environment construction
- Doris学习笔记之监控
- MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
- 快速掌握并发编程 --- 基础篇
猜你喜欢

MySQL事务隔离级别详解

CentOS7 - yum install mysql

MySQL database installation (detailed)

STM32HAL library modifies Hal_Delay to us-level delay
![[Linear Neural Network] softmax regression](/img/98/ffdff5e96ad0d6ac0142af7ca11e9a.png)
[Linear Neural Network] softmax regression

DVWA shooting range environment construction

MySQL forgot password

【debug锦集】Expected input batch_size (1) to match target batch_size (0)

Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis

Heavyweight | The Open Atomic School Source Line activity was officially launched
随机推荐
Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)
MySQL database backup
Three oj questions on leetcode
Heavyweight | The Open Atomic School Source Line activity was officially launched
MySQL开窗函数
精解四大集合框架:List 核心知识总结
C Implementation of Simple Network File Copy
MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
Workflow番外篇
【云原生】DevOps(五):集成Harbor
mysql stored procedure
[Linear Neural Network] softmax regression
Lua,ILRuntime, HybridCLR(wolong)/huatuo热更新对比分析
wx.miniProgram.navigateTo在web-view中跳回小程序并传参
[Detailed explanation of ORACLE Explain]
矩池云快速安装torch-sparse、torch-geometric等包
SQL statement to range query time field
ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
Visual studio shortcuts that improve efficiency, summary (updated from time to time)
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions