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.
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.
Adding a setter method for the field works like a charm
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