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时,一般是因为在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里面自带的方法,推荐使用。
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错误
1.a different object with the same identifier value was already associated with the session. 错误原因:在h ...
- hibernate中一种导致a different object with the same identifier value was already associated with the session错误方式及解决方法
先将自己出现错误的全部代码都贴出来: hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8"?> ...
- a different object with the same identifier value was already associated with the session:
hibernate操作: 实例化两个model类,更新时会提示 a different object with the same identifier value was already assoc ...
- Hibernate Error: a different object with the same identifier value was already associated with the session
在执行Hibernate的Update操作时,报错:a different object with the same identifier value was already associated w ...
- Exception 06 : org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session :
异常名称: org.hibernate.NonUniqueObjectException: A different object with the same identifier value was ...
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
保存实体异常 https://blog.csdn.net/zzzz3621/article/details/9776539 org.hibernate.NonUniqueObjectException ...
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session异常解决办法
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was alread ...
- Hibernate更新数据报错:a different object with the same identifier value was already associated with the session: [com.elec.domain.ElecCommonMsg#297e35035c28c368015c28c3e6780001]
使用hibernate更新数据时,报错 Struts has detected an unhandled exception: Messages: a different object with th ...
随机推荐
- 用CorelDRAW等分分割图片的方法
在CorelDRAW中,想要将图片等分分割可以通过放置容器来实现,根本不需要裁剪工具和辅助线.例如两等分:首先要建立确定等分的份数,建立长方形或正方形.然后把图片放置容器,调整位置,做无缝拼接就可以了 ...
- iScroll知识点
1.如果你有一个复杂的DOM结构,最好在onload事件之后适当的延迟,再去初始化iScroll.最好给浏览器100或者200毫秒的间隙再去初始化iScroll. 2.iScroll作用于滚动区域的外 ...
- 罗辑思维(罗胖)阿瑟·黑利书:《大饭店》、《晚间新闻》、《超载》、《最后诊断》、《钱商》、《身高居位》电子书 pdf和mobi格式得到下载
阿瑟黑利 mobi kindle mobi/txt 1.[智读]_超载.txt 2.[智读]_大饭店 - 阿瑟·黑利.mobi 3.[智读]_钱商 - [加拿大]阿瑟·黑利.mobi 4.[智读]_身 ...
- hosts立即生效的方法
做web开发和测试的,难免需要经常修改hosts来指定某个域名访问某个特定的IP:在windows中,每次修改了C:\windows\system32\drivers\etc\hosts,都需要重启 ...
- phpmyadmin修改root密码
很多人利用phpmyadmin或者命令行来修改了mysql的root密码,重启 后发现mysql登录错误,这是为什么呢?修改mysql的root的密码要在mysql软件中mysql数据库里修改root ...
- gcc警告: warning: dereferencing type-punned pointer will break strict-aliasing rules
Q: 在高优化级别下,不同类型指针之间的强制类型转换可能会触发以下警告: warning: dereferencing type-punned pointer will break strict-al ...
- linux中service *** start与直接运行/usr/bin/***的区别
在linux想要运行启动一个服务有两种方法: 1,运行/etc/init.d/目录下的shell脚本,还可以有快捷方式,service *** start/ stop/restart /status, ...
- [经验交流] docker in docker 的变通实现方法
最近在做CI持续集成环境的容器化,其中一个工作是:在容器中构建容器镜像. 对于这个需求,网上有一些 Docker in Docker 的方法,具体需要修改宿主机的配置.这种方式在单机环境下.对安全要求 ...
- Files 的值“ < < < < < < < .mine”无效。路径中具有非法字符。
出现这个问题的原因是,用svn时,发生了冲突.解决方法:先解决代码冲突,然后在你的工程OBJ/DEBUG目录下,找到 工程名.csproj.FileListAbsolute.txt的文件打开并删除含有 ...
- 5. Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...