在什么情况下通过 Hibernate 从 @OneToMany 关系中明确排除乐观锁定是合适的?
我一直在阅读有关 Hibernate 的帖子,其中基本上说对子实体的任何更新都会导致对父实体的乐观锁定,这通常是不需要的。这里的关键词通常是......谁能更准确地解释你何时需要或不需要乐观锁定这样的关系?
以下是演示乐观锁排除的代码示例:
// Bars - these are specifically excluded from optimist lock
// for the object, since we don't want to obtain optimistic
// lock when we add a new bar
@OptimisticLock(excluded = true)
@OneToMany
@JoinColumn(name = "FOO_ID", nullable = false, updatable = false)
private List<FooBar> bars = new LinkedList<FooBar>();