我有以下实体结构:
public abstract class BaseEntity {
private int _version;
public BaseEntity() {
}
@Version
@Column(name = "oplock", nullable = false)
private int getVersion() {
return _version;
}
@SuppressWarnings("unused")
private void setVersion(final int version) {
_version = version;
}
//some other code goes here....
}
具体实体:
@Table(name="my_table", schema="public",
uniqueConstraints=@UniqueConstraint(columnNames={"username", "attribute"})
)
public class MyEntity extends BaseEntity implements java.io.Serializable {
private int id;
private String username;
private String attribute;
private String op;
private String value;
public MyEntity() {
}
//some code goes here ....
}
现在,我从数据库中选择MyEntity
类型的实体,用entityManager.lock(myEntityInstance, LockModeType.OPTIMISTIC);
锁定它,修改它,并保持修改。我期望获得的是让oplock
列的值递增(oplock
是版本列),但它不受影响。
问题:行为正确还是遗漏了什么?我认为正确的行为是oplock
的值会增加。
编辑:我从hibernate
3.6切换到hibernate
4.1后,我仍然会遇到相同的行为。