What is and what is JPA's Optimistic Locking Field? I noticed that this option exists for Eclipse Link and for Hibernate and this function is enabled when annotating a version attribute within an entity class, but I do not understand what its purpose is, when to use it and what its advantages. >
Example class annotated with @version
@Entity
public class Inventory {
@Id
@Column(name="ITEM_SKU", insertable=false, updatable=false)
protected long id;
@OneToOne
@JoinColumn(name="ITEM_SKU")
protected Item item;
...
@Version
protected int version;
...
public void setItem(Item item) {
this.item = item;
this.id = item.getSKU();
}
}