I am doing batchWriteItem operation on multiple tables of DynamoDb. My code is as follows -
BatchWriteItemOutcome outcome = null;
try {
TableWriteItems userTableWriteItems = new TableWriteItems("User")
.withHashAndRangeKeysToDelete("clientAccountKey", "userKey", clientAccountKey, "xyzUserKey"); // Working for this Method
TableWriteItems PosTrackingWriteItems = new TableWriteItems("PosTracking")
.withHashOnlyKeysToDelete("userKey", "xyzUserKey"); // ** Not Working for this **
outcome = dynamoDb.batchWriteItem (
userTableWriteItems,
PosTrackingWriteItems);
}
catch(Exception e){
System.out.println("Exception in Removing User Data !!! ");
e.printStackTrace();
}
If I just specify batchWrite delete withHashAndRangeKeysToDelete
method where I specify Hash and Range key both, it is working.
But its not working for withHashOnlyKeysToDelete
method where I specify HashKey name and HashKey Value as paramerters. I keep getting this exception:
com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: The provided key element does not match the schema. Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException.
My PosTracking table has HashKey (String) as userKey and I am passing String from the method as well. I have a GSI also in this table with name clientAccountKey (String). I tried using addHashOnlyPrimaryKeysToDelete
& .addPrimaryKeyToDelete
methods also for TableWriteItems but its not working either.