在使用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>();