sunmingtao / sample-code

3 stars 4 forks source link

DynamoDB: The provided key element does not match the schema #267

Closed sunmingtao closed 3 years ago

sunmingtao commented 3 years ago

Unable to persist data into dynamoDB table.

The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: A8MU7EM6I8NG0VGKFBM0VGIHK7VV4KQNSO5AEMVJF66Q9ASUAAJG)
        at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1695) ~[aws-java-sdk-core-1.11.443.jar:na]

Entity

@DynamoDBHashKey
public long getId() {
    return id;
}
sunmingtao commented 3 years ago

DynamoDB cannot have type long as hash key. It needs to be a string.

@DynamoDBHashKey
public String getId() {
    return id;
}

Note, changing the annotation to @DynamoDBRangeKey also doesn't work