当前位置:网站首页>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进程都杀死了
最后又重启了一下服务,才得以解决。
边栏推荐
- 2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。
- 110道 MySQL面试题及答案 (持续更新)
- Create componentized development based on ILRuntime hot update
- MySQL-Explain详解
- Visual studio shortcuts that improve efficiency, summary (updated from time to time)
- MySQL忘记密码怎么办
- Temporal介绍
- Linux系统安装mysql(rpm方式安装)
- mysql uses on duplicate key update to update data in batches
- Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
猜你喜欢

PWN ROP

Linux系统安装mysql(rpm方式安装)

CentOS7 install MySQL graphic detailed tutorial

CentOS7 —— yum安装mysql

MYSQL一站式学习,看完即学完

Shell重油常压塔模拟仿真与控制

Centos7 install mysql5.7

Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work

Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
![[debug highlights] Expected input batch_size (1) to match target batch_size (0)](/img/b3/ff6ccc3cd307befad3bd07a9f4a956.png)
[debug highlights] Expected input batch_size (1) to match target batch_size (0)
随机推荐
matlab simulink欠驱动水面船舶航迹自抗扰控制研究
MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
DVWA shooting range environment construction
面试官竟然问我怎么分库分表?幸亏我总结了一套八股文
centos7安装mysql5.7
mysql stored procedure
MySQL optimization slow log query
Unity Framework Design Series: How Unity Designs Network Frameworks
Interview | Cheng Li, CTO of Alibaba: Cloud + open source together form a credible foundation for the digital world
Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
Apache DButils使用注意事项--with modifiers “public“
剑指offer专项突击版第15天
Pytorch教程Introduction中的神经网络实现示例
.NET-9. A mess of theoretical notes (concepts, ideas)
[Cloud Native] DevOps (5): Integrating Harbor
C Implementation of Simple Network File Copy
MySQL开窗函数
12 reasons for MySQL slow query
Unity shader forge和自带的shader graph,有哪些优缺点?
Workflow番外篇