我目前正在使用 Java dynamoMapper 来创建和查询表。尝试创建具有全局二级索引的表时,出现以下错误
No provisioned throughput specified for the global secondary index
My java class representing the table has this attribute for the global secondary index.
@DynamoDBIndexHashKey(globalSecondaryIndexName="sender")
public String getSender() {
return sender;
}
创建表的类如下所示
public boolean createTable() {
try {
DynamoDBMapper mapper = new DynamoDBMapper(client);
CreateTableRequest tableRequest = mapper.generateCreateTableRequest(entityClass); // 1
tableRequest.setProvisionedThroughput(new ProvisionedThroughput(1000L, 1500L)); // 2
client.createTable(tableRequest); // 3
} catch (Error e) {
e.printStackTrace();
return false;
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
我在 Amazon 网站上搜索了额外的注释和配置,但没有找到 DynamoMapper。无论如何都可以使用 ORM 来执行此操作,还是我必须使用较低级别的 API 手动创建?
最佳答案
您还需要在将生成的每个二级索引表上设置预置吞吐量。
tableRequest.getGlobalSecondaryIndexes().get(0).setProvisionedThroughput(new ProvisionedThroughput(10l, 10l));
关于java - 使用 DynamoMapper 和类 Annotation 创建具有全局二级索引的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36817170/