I was just using batchLoad function of dynamoDB. Here, the documentation
of the function says, the input it takes is List<KeyPair>
. But when I use a KeyPair object, it throws the error that the argument should be a dynamodb annotated class
.
I can use a DynamoDB class, where I set only hashKey and rangeKey
attributes of the class and pass them as an argument. But now my use case is the Class(DynamoDB annotated), I am using has @NonNull
fields. If I have to pass arguments for this I have to set junk values in them, which is obviously not desirable. Any kind of help/ suggestions ?
Thanks!
Here is the working example.
Summary:-
With model class:-
Map<Class<?>, List<KeyPair>> keyPairForTable = new HashMap<>();
keyPairForTable.put(Movies.class, keyPairList);
Full code:-
public Boolean batchLoadMoviesUsingKeyPair() {
DynamoDBMapper dynamoDBMapper = new DynamoDBMapper(dynamoDBClient);
KeyPair keyPair1 = new KeyPair();
keyPair1.withHashKey(1991);
keyPair1.withRangeKey("Movie with map attribute");
KeyPair keyPair2 = new KeyPair();
keyPair2.withHashKey(2010);
keyPair2.withRangeKey("The Big New Movie 2010");
List<KeyPair> keyPairList = new ArrayList<>();
keyPairList.add(keyPair1);
keyPairList.add(keyPair2);
Map<Class<?>, List<KeyPair>> keyPairForTable = new HashMap<>();
keyPairForTable.put(Movies.class, keyPairList);
Map<String, List<Object>> batchResults = dynamoDBMapper.batchLoad(keyPairForTable);
for (Map.Entry<String, List<Object>> entry : batchResults.entrySet()) {
System.out.println(entry.getKey());
System.out.println(entry.getValue());
}
return true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With