问题描述
有人可以在Hibernate中使用 @Version
和 @Audited
这个用例吗? @Version用于实现与Hibernate,这意味着没有两个事务在冲突的同时覆盖数据。
如果数据被两个线程同时读取,并且都尝试使用不同的值更新同一行,
Hibernate使用 @Version
字段检查该行是否已经更新。
在提交之前,每个事务都会验证没有其他事务修改了其数据。
如果修改,最后一次事务遇到处理陈旧数据错误。
@Audited
用于执行
Could someone help me with the use case when to use @Version
and @Audited
in Hibernate?
@Version is used to implement Optimistic locking with Hibernate, which means that no two transactions override the data at the same time with a conflict.
If the data is read by two threads at the same time, and both try to update the same row with different values,Hibernate uses the @Version
field to check if the row is already updated.
Before committing, each transaction verifies that no other transaction has modified its data.If modified, the last transaction encounters a "Working with stale data" error.
@Audited
is used to perform auditing functionality on entities part of Hiberate Envers
这篇关于何时在Hibernate中使用@Version和@Audited?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!