当前位置:网站首页>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进程都杀死了
最后又重启了一下服务,才得以解决。
边栏推荐
- DVWA shooting range environment construction
- Blockbuster | foundation for platinum, gold, silver gave nameboards donors
- mysql存储过程
- SQL injection of DVWA
- Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis
- sql语句-如何以一个表中的数据为条件据查询另一个表中的数据
- 限流的原理
- Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)
- 快速掌握并发编程 --- 基础篇
- MySQL优化之慢日志查询
猜你喜欢

Multiple table query of sql statement

ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your

Summary of MySQL common interview questions (recommended collection!!!)

城市内涝及桥洞隧道积水在线监测系统

MySQL-如何分库分表?一看就懂

工作流编排引擎-Temporal

MySQL database installation (detailed)

MySQL优化之慢日志查询

mysql uses on duplicate key update to update data in batches

The input input box displays the precision of two decimal places
随机推荐
限流的原理
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
Puzzle Game Level Design: Reverse Method--Explaining Puzzle Game Level Design
<urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍
SQL row-column conversion
【py脚本】批量二值化处理图像
MySQL常见面试题汇总(建议收藏!!!)
The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
MySQL optimization: from ten seconds to three hundred milliseconds
MySQL事务(transaction) (有这篇就足够了..)
PCL calculates the point cloud coordinate maximum and its index
如何将项目部署到服务器上(全套教程)
sql语句-如何以一个表中的数据为条件据查询另一个表中的数据
一文了解大厂的DDD领域驱动设计
剑指offer专项突击版第15天
MySQL-如何分库分表?一看就懂
1. Get data - requests.get()
110道 MySQL面试题及答案 (持续更新)
【debug锦集】Expected input batch_size (1) to match target batch_size (0)
mysql使用on duplicate key update批量更新数据