首页 \ 问答 \ Hibernate saveOrUpdate行为(Hibernate saveOrUpdate behavior)

Hibernate saveOrUpdate行为(Hibernate saveOrUpdate behavior)

有没有人知道当session.saveOrUpdate()被调用时,Hibernate如何知道是INSERT还是更新数据库中的值?

到目前为止,我只确定它不依赖于缓存中的信息,并且数据库中实体的存在由主键决定。


Does anyone know how Hibernate knows whether to INSERT or to UPDATE a value in the database when session.saveOrUpdate() is called?

So far, I have only determined that it is not dependent on the information in the cache, and that the existence of the entity in the database is determined by the primary key.


原文:https://stackoverflow.com/questions/6443672
更新时间:2023-10-03 06:10

最满意答案

在保存映像之前,将执行已注册的关闭操作。 这意味着源文件已关闭,Web服务器将关闭。 保存映像后,它会执行启动操作,这通常会再次启动Web服务器。 根据服务器实现,可能会关闭打开的连接。

这意味着您在保存图像时无法接受新连接,并且可能会暂时挂起或关闭打开的连接。 对于这两个问题,(至少)有两个简单的解决方法:

  1. 在保存之前使用OSProcess分割图像(DabbleDB,CmsBox)。

  2. 使用多个映像和负载平衡器,以便在保存之前可以从活动服务器中一次删除一个映像。


Before an image is saved registered shutdown actions are executed. This means source files are closed and web servers are shut down. After the image is saved it executes the startup actions, which typically bring up the web-server again. Depending on the server implementation open connections might be closed.

This means that you cannot accept new connections while you save an image and open connections might be temporarily suspended or closed. For both issues there are (at least) two easy workarounds:

  1. Fork the image using OSProcess before you save it (DabbleDB, CmsBox).

  2. Use multiple images and a load balancer so that you can remove images one at a time from the active servers before saving them.

相关问答

更多
  • 在保存映像之前,将执行已注册的关闭操作。 这意味着源文件已关闭,Web服务器将关闭。 保存映像后,它会执行启动操作,这通常会再次启动Web服务器。 根据服务器实现,可能会关闭打开的连接。 这意味着您在保存图像时无法接受新连接,并且可能会暂时挂起或关闭打开的连接。 对于这两个问题,(至少)有两个简单的解决方法: 在保存之前使用OSProcess分割图像(DabbleDB,CmsBox)。 使用多个映像和负载平衡器,以便在保存之前可以从活动服务器中一次删除一个映像。 Before an image is sav ...
  • 你只需要复制.image和.changes文件。 只要它们保持在一起并具有相同的根名称,那么你应该很好。 或者,如果从世界菜单中选择“另存为..”,则可以用新名称创建两个文件的备份副本。 (尽管这会改变当前正在运行的实例使用的名称,所以如果你只是备份,那么你会想在这之后立即退出)。 You just need to copy the .image and .changes files. As long as they're kept together and have the same root name, ...
  • 只需等待有人发布一个新的。 情况就是这样,因为核心更新时额外的包可能会中断,我们无法控制它。 这不是最佳的,但目前我们不能做得更好。 Simply wait that somebody release a new one. The situation is like that since extra packages could break when core is updated and we could not control it. This is not optimal but for now we ...
  • 尝试alt+. (Linux)或cmd+. (OS X)。 这应该触发用户中断并打开调试器(您可能需要连续几次按键组合键)。 较旧的Seaside版本也曾用于通过/seaside/config公开的Web界面暂停和恢复UI过程。 不确定是否仍然可以。 Try alt+. (Linux) or cmd+. (OS X). That should trigger a user interrupt and open a debugger (you'll possibly need to hit the key c ...
  • 所有非核心Pharo图像都有一个用于构建该图像的脚本。 只需编辑该文件并将其拖放到新的核心上即可。 你也可以告诉我你在Pharo图像中不喜欢什么,这样我就可以增强它们。 With all non-core Pharo images come a script which was used to build that image. Just edit that file and drag&drop it on a new core. You could also tell me what you don't ...
  • 一种可能性是你填写了一个类绑定。 检查以下内容以获取nil的键和值列表: Smalltalk globals associations select: [ :assoc | assoc value isNil or: [ assoc key isNil ] ]. 顺便说一下:如果你附上了一个屏幕截图,那么如果你附上了一个屏幕截图。 要获得堆栈跟踪,请右键单击堆栈列表中最顶端的条目(在屏幕截图中选择的条目),然后选择“复制到剪贴板”。 然后在此处粘贴内容(或至少前30帧)。 更新 A ...
  • 请尝试以下方法: promiseLock := Semaphore new. [ [[promiseValue := aBlock value] on: Error do: [:err | promiseError := err]] ensure: [promiseLock signal]] forkAt: Processor userBackgroundPriority 我们的想法是ensure:即使Error限制了对aBlock的评估, aBlock signal量也会收到一个signal ...
  • 内存不足的原因是在处理之前将整个文件读入内存。 由于您无论如何只能通过网络发送数据块,因此您也应该一次只读取一个数据块(这就是流的目的)。 所以不是这样的: myStream := (FileStream oldFileNamed: 'big_buck_bunny_480p_surround-fix.avi'). bytes := myStream next: myStream size. myStream close. 你应该使用这样的东西: blockSize := 128. myStream ...
  • 首先,我想强调一下,如果配置在ConfigurationOf 类中,您可以使用#configuration消息加载它: Gofer new smalltalkhubUser: 'Moose' project: 'Glamour'; configuration; load. (Smalltalk at: #ConfigurationOfGlamour) perform: #loadDefault. 我没看到你的项目,我可以建议你手工编写配置。 Metacello有一个名为D ...
  • 我永远无法安装JNIPort,但Masashi Umezawa准备了安装了JNIPort的Pharo 1.4映像。 你可以在这里找到它: http://share.cx.com/Cgpfpv 我知道这不是你想要的答案,但至少你会有一个带有JNIPort的Pharo图像,所以你可以马上开始工作...... I could never install JNIPort, but Masashi Umezawa prepared a Pharo 1.4 image with JNIPort installed in ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)