I'm new to DynamoDB and trying out a sample scenario using Transaction support. I'm using the same entity provided in dynamodb-transaction library. Only difference is I've added a range key with the hash key. Here's the table definition:
ItemId
--> hash key , stringItemName
--> range key, string
@DynamoDBTable(tableName = "Item")
public static class ExampleItem {
private String itemId;
private String value;
private String itemName;
private Long version;
@DynamoDBHashKey(attributeName = "ItemId")
public String getItemId() {
return itemId;
}
public void setItemId(String itemId) {
this.itemId = itemId;
}
@DynamoDBRangeKey(attributeName="ItemName")
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@DynamoDBVersionAttribute
public Long getVersion() {
return version;
}
public void setVersion(Long version) {
this.version = version;
}
}
As you can see, I'm using the version attribute as well. Now, I'm trying to execute a simple create or update scenario using transaction/dbmapper. Here's the code snippet.
Transaction t1 = txManager.newTransaction();
ExampleItem keyItem = new ExampleItem();
keyItem.setItemId("Item1");
keyItem.setItemName("USA");
ExampleItem item = t1.load(keyItem);
if (item != null) {
item.setValue("Magenta");
item.setItemName("UK");
t1.save(item);
} else {
item = new ExampleItem();
item.setItemId(keyItem.getItemId());
item.setItemName("USA");
item.setValue("Violet");
t1.save(item);
}
t1.commit();
t1.delete();
I'm able to add the record without any issue, but I'm having a problem when I'm trying to read the record and update any attribute. I'm getting the following exception:
Uncaught exception:com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException: Status Code: 0, AWS Service: null, AWS Request ID: null, AWS Error Code: null, AWS Error Message: Item {ItemId={S: Item1,}, ItemName={S: UK,}} had unexpected attributes: Status Code: 0, AWS Service: null, AWS Request ID: null, AWS Error Code: null, AWS Error Message: expected attribute(s) {version={Value: {N: 1,},Exists: true}} but found null
com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException: Status Code: 0, AWS Service: null, AWS Request ID: null, AWS Error Code: null, AWS Error Message: Item {ItemId={S: Item1,}, ItemName={S: UK,}} had unexpected attributes: Status Code: 0, AWS Service: null, AWS Request ID: null, AWS Error Code: null, AWS Error Message: expected attribute(s) {version={Value: {N: 1,},Exists: true}} but found null
Looks like it has something to do with version, but not sure where am I going wrong. Any pointers will be appreciated.
-Thanks
Shamik