6

Executing orderRequestDao.save(new OrderRequest("5000", "body")); successfully places a record in Dynamo. Any attempts to read returns:

[Request processing failed; nested exception is com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException:
could not invoke null on class 
com.cfa.fulfillmentApi.model.OrderRequest 
with value 100 of type class java.lang.String] with root cause

(Record with id: 100 exists)

I'm using the following jars (aws.sdk.version: 1.11.86):

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>${aws.sdk.version}</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-core</artifactId>
        <version>${aws.sdk.version}</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-dynamodb</artifactId>
        <version>${aws.sdk.version}</version>
    </dependency>
    <dependency>
        <groupId>com.github.derjust</groupId>
        <artifactId>spring-data-dynamodb</artifactId>
        <version>4.4.1</version>
    </dependency>

DyamoDb config:

Primary partition key: id (String)

Dao:

@EnableScan
public interface OrderRequestDao extends CrudRepository<OrderRequest, String> {
    OrderRequest findOne(String s);
    OrderRequest save(OrderRequest or);
}

Domain object:

@DynamoDBTable(tableName = "dev_transx")
public class OrderRequest {

    private String id;
    private String body;

    public OrderRequest(String id, String body) {
        this.id = id;
        this.body = body;
    }

    public OrderRequest() {}

    @DynamoDBHashKey
    public String getId()
    {
        return id;
    }

    @DynamoDBAttribute
    public String getBody()
    {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    @Override
    public String toString() {
        return String.format(
                "Customer[id=%d, body='%s']",
                id, body);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

}

I've tried just about every data type for id in the domain class, but no luck.

3 Answers 3

13

I removed aws-java-sdk-dynamodb since it was already in spring-data-dynamodb

Most importantly I added a setter for ID in the domain class.

8

Adding a setter method for the field works like a charm

0

For those who like me found this question through the error message but are not happy with all proposed solutions:

Annotate the getter method which cause the problem with @DynamoDBIgnore

Excerpt from AWS documentation:

Annotation for marking a class property as non-modeled. Applied to the getter method or the class field for a non-modeled property. If the annotation is applied directly to the class field, the corresponding getter and setter must be declared in the same class.

All getter methods not marked with this annotation are assumed to be modeled properties and included in any save() requests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.