如弹簧数据沙发库参考指南中所述,我正在尝试使用 @Version 注释启用乐观锁定功能。我的期望是当文档发生突变时,couchbase 将填充版本字段。但似乎它没有填充版本字段。它始终为 0。以下是我的 Pojo,并使用 crudRepository 保存文档。当我更新时,我尝试将版本发送为 1 以模拟优化锁定异常。但我没有得到任何异常更新顺利。由于文档没有多大帮助,我无法继续进行。任何帮助将不胜感激?
@Document
public class Project extends BusinessEntity {
private static final long serialVersionUID = 1665165729053936288L;
@NotNull
@Field
private String name;
@Field
private String description;
@Version
private long version;
public Project() {
}
public Project(String name) {
this.name = name;
}
public Project(String name, String description) {
super();
this.name = name;
this.description = description;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @return the version
*/
public long getVersion() {
return version;
}
/**
* @param version the version to set
*/
public void setVersion(long version) {
this.version = version;
}
}