I have a DAO like:
@Getter
@Setter
@DynamoDBTable(tableName="tableName")
public class DAO {
@DynamoDBHashKey
private String field1;
@DynamoDBIndexHashKey(globalSecondaryIndexName="index_name")
@DynamoDBRangeKey
private String field2;
}
Problem is when I am trying to use the DAO to make a load call using DynamoDBMapper with field1 as the hash key to obtain the item, it throws a DynamoDBException saying: Null key found for public DAO.getField2() but actually table has value corresponding to field2. Question, is this because of Lombok annotation instead of the manual mutator code and or in general we use Lombok and DynamoDBAnnotations together?
DynamoDBDocument. Indicates that a class can be serialized as an Amazon DynamoDB document. For example, suppose that you wanted to map a JSON document to a DynamoDB attribute of type Map ( M ). The following code example defines an item containing a nested attribute (Pictures) of type Map.
The DynamoDBMapper class is the entry point to Amazon DynamoDB. It provides access to a DynamoDB endpoint and enables you to access your data in various tables. It also enables you to perform various create, read, update, and delete (CRUD) operations on items, and run queries and scans against tables.
A converter which wraps a source and target converter. static class. DynamoDBTypeConverter.NullSafeConverter<S,T> A converter which evaluates nullability before convert/unconvert.
Annotation Type DynamoDBIndexHashKeyAnnotation for marking a property in a class as the attribute to be used as the hash key for one or more global secondary indexes on a DynamoDB table. Applied to the getter method or the class field for the index hash key property.
Here is a little more of an explanation and a TL;DR
You are calling the load
method, which is mapped to the GetItem
call. The DynamoDBMapper
is trying to map that request based on your annotations. Your class has the @DynamoDBRangeKey
annotation, and the GetItem
call needs the full primary key to get the item, which means that the mapper will build out the primary key for the object.
Since Lombok has already generated your code (before runtime), it is not affecting the annotations you have already placed. And also since your annotations are on the fields rather than applying them to the getters, the mapper it is calling the generated Lombok getter. When it tries to serialize into a request, however, that getter is returning null
because you have only set the hashKey.
TL;DR: load()
translates to GetItem
API which requires both the hashKey and the rangeKey since both annotations are present on your class.
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