我是DynamoDB的新手,我正在尝试插入一个新项目。但是,我得到以下例外:
com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: XXX)
这是我的表格描述:
{
"Table": {
"TableArn": "arn:aws:dynamodb:us-east-1:111:table/table-XXX",
"AttributeDefinitions": [
{
"AttributeName": "timestamp",
"AttributeType": "S"
},
{
"AttributeName": "title",
"AttributeType": "S"
}
],
"ProvisionedThroughput": {
"NumberOfDecreasesToday": 0,
"WriteCapacityUnits": 5,
"ReadCapacityUnits": 5
},
"TableSizeBytes": 0,
"TableName": "ddb-table-sst67gy",
"TableStatus": "ACTIVE",
"KeySchema": [
{
"KeyType": "HASH",
"AttributeName": "title"
},
{
"KeyType": "RANGE",
"AttributeName": "timestamp"
}
],
"ItemCount": 0,
"CreationDateTime": 1489090172.658
}
}
这是我的Java类:
@DynamoDBTable(tableName = "table-XXX")
public class Movie {
private String title;
private String timeStamp;
@DynamoDBHashKey(attributeName = "title")
@NotNull(message = "Title must not be empty")
public String getTitle() {
return title;
}
public Movie withTitle(String name) {
setTitle(name);
return this;
}
@DynamoDBAttribute(attributeName = "timestamp")
public String getTimeStamp() {
return timeStamp;
}
public Movie withTimeStamp(String address) {
setTimeStamp(address);
return this;
}
public void setTitle(String title) {
this.title = title;
}
public void setTimeStamp(String timeStamp) {
this.timeStamp = timeStamp;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Movie movie = (Movie) o;
if (title != null ? !title.equals(movie.title) : movie.title != null) return false;
return timeStamp != null ? timeStamp.equals(movie.timeStamp) : movie.timeStamp == null;
}
@Override
public int hashCode() {
int result = title != null ? title.hashCode() : 0;
result = 31 * result + (timeStamp != null ? timeStamp.hashCode() : 0);
return result;
}
}
我应该如何正确地将我的Java类映射到DynamoDB?
答案 0 :(得分:0)
请使用注释@DynamoDBRangeKey
来定义范围或排序键属性。
@DynamoDBRangeKey(attributeName = "timestamp")
public String getTimeStamp() {
return timeStamp;
}