我正在使用DynamoDB SDK 1.11.185版本。我有一個Client實體通過DynamoDBMapper註釋映射到客戶端DynamoDB表。其中一個屬性包含嵌套值(請參閱下面的代碼示例)。我想從Options類中添加一個本地二級索引到zone屬性。有一次,我要保存一個對象,我從這個類DynamoDBMapper - DynamoDBDocument和本地二級索引
com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperTableModel
線415看起來像從庫中的錯誤得到了一個空指針異常。
P.D.如果我通過Client實體的clientId屬性生成索引,一切正常。
@DynamoDBTable(tableName="Clients")
public class Client {
private String id;
private String clientId;
private Date created;
private Options options;
public Client() {
}
public Client(String id, String clientId, Options options) {
this.id = id;
this.clientId = clientId;
this.options = options;
this.created = new Date();
}
@DynamoDBHashKey
public String getId() { return id; }
public void setId(String id) { this.id = id; }
@DynamoDBAttribute
public String getClientId() { return clientId; }
public void setClientId(String clientId) { this.clientId = clientId; }
@DynamoDBAttribute
public Options getOptions() { return options; }
public void setOptions(Options options) { this.options = options; }
@DynamoDBRangeKey
public Date getCreated() { return created; }
public void setCreated(Date created) { this.created = created; }
}
@DynamoDBDocument
public class Options {
private String zone;
public Options() {
}
public Options(String zone) {
this.zone = zone;
}
@DynamoDBIndexRangeKey(localSecondaryIndexName = "zone-index")
public String getZone() { return zone; }
public void setZone(String zone) { this.zone = zone; }
}
****************************編輯************** ***********
通過@Raniz正確答案和 Indexing on nested field
它可以使用JSON來完成,雖然屬性: DynamoDB create index on map or list type
感謝@Raniz回答。其實我只是發現我的問題在這裏回答https://stackoverflow.com/questions/30439107/indexing-on-nested-field。我會嘗試使用你提出的方法並回到你身邊。標記它是正確的,但。 – alvgarvilla