The update
action in Grails first checks for the version of the object to be updated and then updates it.
What part of Grails ensures that the object isn t updated by another request during checking the version and updating the object?
<强> 更新: 强>
是的, 冬眠将在保存对象时检查版本, 并会丢出一个例外是乐观锁定失败。 我想冬眠会确保检查+更新是原子, 但是...
如果您查看一下生成的更新方法, 您就会发现, 第一次重复检查后( 从我的角度), (然后) ( 从我的观点) 将无法处理例外 。 在更新方法已经检查过正确版本后, 冬眠会丢出例外的可能性很小, 但对我来说是可能的 。
试一试省钱,抓住例外(如果有例外),难道还不够吗?