The entity i am querying has a HashKey & a RangeKey (Number). When i use batchGetItem on it, i get the following error:
AWS Error Code: ValidationException, AWS Error Message: One or more parameter values were invalid: Mismatching attribute types between location and schema
Schema:
Table: Daily
Hash Key: CustId (String)
Range Key: Dated (Number)
Data:
CustId : VisioNerdy
Dated : 1329071400000
Code:
List<Key> fkeys = new ArrayList<Key>(); //tableName="Daily", keys=["VisioNerdy"], ranges=[1329071400000] Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>(); for(int i = 0; i < keys.size(); i++) { String key = keys.get(i); if(ranges == null) fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key))); else fkeys.add(new Key().withHashKeyElement(new AttributeValue().withS(key)) .withRangeKeyElement(new AttributeValue().withS(ranges.get(i).toString()))); } requestItems.put(tableName, new KeysAndAttributes().withKeys(fkeys)); BatchGetItemRequest batchGetItemRequest = new BatchGetItemRequest().withRequestItems(requestItems); BatchGetItemResult result = client.batchGetItem(batchGetItemRequest);
Any clues?
You have defined the range attribute of your Hash and Range Type Primary Key as type Number, yet prepare its attribute value via
withS()as type String for your request:Changing withS(String s) to withN(String s) should remedy your problem accordingly (confusingly both methods require a parameter of type String):
Admittedly, the implicit weak typing of the DynamoDB data types submission based on String parameters only doesn’t exactly ease developing 😉