gpt4 book ai didi

hibernate - Hibernate 的 "unsaved-value mapping was incorrect"是什么意思?

转载 作者:行者123 更新时间:2023-12-04 01:00:22 27 4
gpt4 key购买 nike

有一个著名的异常(exception):

org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [my.Entity#123456]



当“行被另一个事务更新或删除”时,这是一种非常熟悉的情况。

但是什么意味着另一种可能性 - “未保存的值映射不正确”?以及如何有意重现这种情况?

Grails 2.2.0

最佳答案

有关未保存值的说明,请参阅 http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#mapping-declaration-id :

unsaved-value (optional - defaults to a "sensible" value): an identifier property value that indicates an instance is newly instantiated (unsaved), distinguishing it from detached instances that were saved or loaded in a previous session.



在极少数情况下,当 saveOrUpdate() 无法确定实体是新实体还是已分离实体时,Hibernate 需要这样做。

如果一个实体通过您未保存的值确定为分离的,而是新的,那么 hibernate 无法比较版本号(因为该实体不存在于数据库中)。但是 Hibernate 无法知道您的未保存值映射是否不正确,或者实体是否已在另一个事务中被删除。这也在 org.hibernate.StaleStateException 中描述:

Thrown when a version number or timestamp check failed, indicating that the Session contained stale data (when using long transactions with versioning). Also occurs if we try delete or update a row that does not exist.

关于hibernate - Hibernate 的 "unsaved-value mapping was incorrect"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24827576/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com