问题描述
有一个著名的例外:
当行被另一笔交易更新或删除"时,这是一种非常熟悉的情况.
This is a very familiar situation when "row was updated or deleted by another transaction".
但是,另一种可能性是什么-未保存的值映射不正确"?以及如何有意地重现这种情况?
But what means another possibility - "unsaved-value mapping was incorrect"? And how to reproduce such situation intentionally?
Grails 2.2.0
Grails 2.2.0
推荐答案
有关未保存值的说明,请参见 http://docs.jboss.org/hibernate/core/3.6/reference/zh-CN/html/mapping.html#mapping-声明ID :
For a description of unsaved-value see http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#mapping-declaration-id:
在极少数情况下,当saveOrUpdate()无法确定实体是新实体还是分离实体时,Hibernate需要此功能.
Hibernate needs this in rare cases, when saveOrUpdate() is not able to determine if the entity is new or detached.
如果一个实体是通过您的未保存值确定为分离的,但它是新的,则hibernate无法比较版本号(因为该实体在数据库中不存在).但是Hibernate无法知道您的未保存值映射是否正确或该实体已在另一笔交易中删除. org.hibernate.StaleStateException中也对此进行了描述:
If an entity is determined by means of your unsaved-value as detached, but is instead new, then hibernate can't compare the version numbers (because the entity just doesn't exist in the database). But Hibernate can't know if your unsaved-value mapping is not correct or the entity has been deleted in another transaction. This is described in org.hibernate.StaleStateException as well:
这篇关于Hibernate的“未保存值映射不正确"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!