我剛剛開始一個使用CouchBase 4.5和Spring Data CouchBase的新項目。我有一個看起來像這樣的實體:我如何讓Spring Data Couchbase堅持ID字段?
@Document
public class ItemType implements Serializable {
private static final long serialVersionUID = -874553420214538944L;
@Id
@Field
private String key;
@Field
private String displayName;
@Field
private int appAccountId;
@Field
private Map<String, FieldType> fieldTypes;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public int getAppAccountId() {
return appAccountId;
}
public void setAppAccountId(int appAccountId) {
this.appAccountId = appAccountId;
}
public Map<String, FieldType> getFieldTypes() {
return fieldTypes;
}
public void setFieldTypes(Map<String, FieldType> fieldTypes) {
this.fieldTypes = fieldTypes;
}
}
當我把它用CouchBase CrudRepository保存,蜿蜒像這樣的DB:
{
"_class": "com.mycompany.models.ItemType",
"appAccountId": 2,
"displayName": "Image - External",
"fieldTypes": {
"location": {
"rank": 1,
"type": "String",
"publishCascade": false,
"displayName": "Location",
"displayAttributes": {
"uiDisplayType": "TEXT_FIELD"
}
}
}
}
一切都顯得精細,除了「重點」領域沒有被保留在文檔中。我已經嘗試過使用和不使用@Field批註,但結果是一樣的。有沒有什麼辦法可以確保@Id字段被保存到數據庫?
那麼我們如何將獨立文檔的引用添加到我們當前的文檔中? – talhaocakci