Reputation: 23
I am working with SpringBoot application that does CRUD operation on aws dynamoDB, and I have entity class that has structure of the following
// getter, setter, args, no args annotation here
@DynamoDBTable(tableName = "TableName")
public class Entity {
@DynamoDBHashKey(attributeName = "PartitionKey")
private String key;
@DynamoDBRangeKey(attributeName = "SortKey")
private String tempSortKey;
@DynamoDBAttribute(attributeName = "Value")
private String tempValue;
@DynamoDBAttribute(attributeName = "TerminationDate")
private Date tempTerminationDate;
// bunch of other variables and attributes
// Repository
public Entity savEntity(Entity entity) {
dynamoDBMapper.save(entity);
return entity;
}
// Controller
//Controller Class
@PostMapping(value="URL")
public Entity saveItem(@RequestBody Entity key) {
return Repository.saveKeyValue(key);
I get an error and the error message is: "Unable to unmarshall exception response with the unmarshallers provided (Service: AmazonDynamoDBvZ; Status Code: 400; Error Code: ValidationException".
I have made sure that PartitionKey is of type string and sort key is not selected when dynamoDB was first created and I do not have access to either create or modify the table. Other thing I tried was to change the entity class like so
// getter, setter, args, no args annotation here
@DynamoDBTable(tableName = "TableName")
public class Entity {
@DynamoDBHashKey(attributeName = "PartitionKey")
@DynamoDBAUtogeneratedKey
private String uniquekey;
@DynamoDBAttribute(attributeName="key")
private String key;
@DynamoDBRangeKey(attributeName = "SortKey")
private String tempSortKey;
@DynamoDBAttribute(attributeName = "Value")
private String tempValue;
@DynamoDBAttribute(attributeName = "TerminationDate")
private Date tempTerminationDate;
// bunch of other variables and attributes
This works fine but I do not want Autogenerated unique key. I also need Sort key within Table as key might have similar values but sort key will always have unique value.
I also tried having key on two different variable one as HashKey and one as Attribute and that works fine.
Thanks
Upvotes: 1
Views: 164
Reputation: 19883
I have made sure that PartitionKey is of type string and sort key is not selected when dynamoDB was first created and I do not have access to either create or modify the table
My understanding is that you're trying to include a sort key in your data model using annotation @DynamoDBRangeKey
however your actual table was not creates with a sort key and you have no permission to alter/create a new table. Feel free to correct me if I misunderstood.
You're seeing a validation exception as you cannot just add a sort key to your data model of your actual table has not defined one. You need to re-create your table should you wish to include a sort key in your data model.
Unable to unmarshall exception response with the unmarshallers provided
Upvotes: 1