使用 session.merge(object) 解决
示例:
merge和saveorupdate()到底有什么区别呢?看一段代码:
Session session = this.getSession();
Transaction tr = session.beginTransaction();
User exituser = (User)session.get(User.class, new Integer(1)); tr.commit();
session.close();
session = getSession();
tr = session.beginTransaction();
User exituser2 = (User)session.get(User.class, new Integer(1)); session.update(exituser);
tr.commit();
session.close();
运行上面的代码,hibernate给我们报了一个错误:a different object with the same identifier value was already associated with the session。意思是,在session缓存中以两个标识相同的对象,这是不可以的。那么,吧update改成merge会怎么样呢?改为merge后,一切OK,运行正常。其实merge在执行更新之前会将两个标识符相同的对象进行合并,具体合并的方向是向exituser2合并。 注意:
merge方法在执行之前都回去缓存中找是不是有相应的记录,也就是会有一条select语句,执行改语句的目的是为了判断该对象是否被修改了。而update就不管这些,直接就一条update语句。
分享到:
相关推荐
have made the MATLAB?source code for my system publicly available for research and testing purposes. For details of the underlying scientific principles please download my dissertation, available on ...
did-uri 分散身份(DID)URI解析器和格式化程序。 抽象的 在此模块中,我们提供了一个w3兼容接口,用于按照规范的规定来解析和序列化 URI。 该模块提供的接口类似于Node标准库中url模块的接口。... identif
different children providef the impetus for describing a number of fallacies pertaining to psychological tests and the assessment procedure for educational purposes. Among the fallacies identif
Restricted Gene Expression Programming: A New Approach for Parameter Identification Inverse Problems of Partial Differential Equation(CI, EI, 2区IF=2.784)
different children providef the impetus for describing a number of fallacies pertaining to psychological tests and the assessment procedure for educational purposes. Among the fallacies identif
环境:本地主机:ha01eth0: 192.168.1.100 //对外IP地址 远程主机:ha02eth0: 192.168.1.200 //对外IP地址 本地主机ha01配置: 代码如下:[root@ha01 /]# cd /etc/ssh[root@ha01 ssh]# ssh-keygen -...rsa):Your identif
High Speed Line-Scan Machine Vision Automated Vision Systems 的一篇非常周详的设计基础知识理论课程的介绍课件: 教学目标: ...• Describe the basic parts of a line-scan image sensor • Identif
unity插件AllIn1SpriteShader的官方手册,使用付费软件翻译的中英对照pdf
The presented approach in this book to acoustic echo suppression copes as a first of its kind with highly correlated loudspeaker signals of multichannel reproduction systems, does not require a ...
Near-infrared femtosecond Z-scans are carried out on the synthesized gold nanorods (NRs) possessing the average length of 46 nm using a femtosecond laser operated at the wavelength of 800 nm, which ...
RBswappableContainerViewController ,灵感来自 Michael Luton 的博客文章。 我的目标是允许换出内容视图,同时将导航控件保留在父 UIViewController 中。 在您的主 ViewController 中使用很... if ([segue.identif
GIS行业的AE开发,连接SDE数据库,超像原版的Identif,还有一个尚未完成的图片查看功能.肥猫的作业,你懂的~
在设置数据库实例的密码时,注意不要以数字开头,否则您将会遇到 ORA-00988 missing or invalid password (口令缺失或无效) 错误。 Oracle 10g 安装完成后,您可使用 dbca 命令创建新的...SQL> create user zkj identif
摘要:复杂事件描述语言是复杂事件处理研究中的重要组成部分,目前面向无线射频识别(Radio Frequency Identification, RFID)的复杂事件... 随着电子商务和信息技术的发展以及无线射频识别技术(Radio Frequency Identif
摘要:复杂事件描述语言是复杂事件处理研究中的重要组成部分,目前面向无线射频识别(Radio Frequency Identification, RFID)的复杂事件... 随着电子商务和信息技术的发展以及无线射频识别技术(Radio Frequency Identif
摘要:RFID 应用系统种类繁多,开发工作上具有一定的重复性,为此通过分析RFID 系统的一般模型,提出了基于构件化封装设计思想的RFID 系统通用开发平台软、硬件模型,利用... 射频识别(RFID,Radio Frequency Identif
摘要:RFID 应用系统种类繁多,开发工作上具有一定的重复性,为此通过分析RFID 系统的一般模型,提出了基于构件化封装设计思想的RFID 系统通用开发平台软、硬件模型,利用... 射频识别(RFID,Radio Frequency Identif
emgr-EMpirical GRamian框架(5.9) | | 版本: 5.9 (2021-01-21) 创建人: 下: 许可 摘要:用于(非线性)输入输出系统的经验系统Gramians。 范围 模型缩减/模型订单缩减(MOR) 非线性模型降阶(nMOR) ...
系统辩识最新综和讲解 非常有帮助对科研工作者
快速准确地鉴别名优茶的真伪是当前茶叶行业亟待解决的一项重大课题。针对这一现状,提出了一种快速准确鉴别名优茶真伪的新思路。试验中,以碧螺春茶为研究对象,利用近红外光谱分析技术结合支持向量机(SVM)模式识别原理...