正如Spring数据沙发根参考指南中所提到的,我正在尝试使用@Version注释启用乐观锁定功能。我的期望是当一个doucument变异时,couchbase会填充版本字段。但似乎没有填充版本字段。它总是0.以下是我的Pojo,并使用crudRepository来保存文档。当我更新我尝试发送版本为1来模拟optimitic锁定异常。但我没有得到任何例外,更新很顺利。由于文档没有多大帮助,我无法继续下去。任何帮助将不胜感激?
@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;
}
}
答案 0 :(得分:0)
我的错。 Couchbase填充版本字段。但我们需要在保存时发送版本号。
答案 1 :(得分:0)
这可能失败的另一个原因是您需要为@version
字段设置一个getter。