Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB mapper: update only not-null properties

I am using the mapper provided by the AWS SDK, with Java. I need to update record on DynamoDB: is there any way, using the mapper, to avoid that a null property of a mapped entity is stored on DynamoDB, overwriting the old value?

I try to explain my question with an example. I have a java entity with three properties: id, a, b. It is mapped to a DynamoDB table with hashKey only, on field id. On DynamoDB it is stored a record {"id":"1", "a":"aa"}. After an update called on an entity with id:1, a:null and b:"bb", I find on DynamoDB a record {"id":"1", "b":"bb"}.

Any solutions?

Thanks

like image 490
Ulisse Avatar asked Aug 14 '13 17:08

Ulisse


1 Answers

You will be very interested in the new SaveBehavior strategy, recently introduced in v1.5.4. The new SaveBehavior strategy is called UPDATE_SKIP_NULL_ATTRIBUTES. This new SaveBehavior is very similar to the existing UPDATE strategy. The only difference is that any attributes sent with null values will not be removed from the item in DynamoDB. Here is the link to the JavaDoc.

like image 96
Wade Matveyenko Avatar answered Sep 21 '22 15:09

Wade Matveyenko