Marcos J.C Kichel
Marcos J.C Kichel

Reputation: 7219

Does flattened objects get automatically updated with @DynamoDBFlattened?

I am very new to NoSQL. I am taking a look at aws-java-sdk-dynamodb and I found this annotation @DynamoDBFlattened that seems to flatten an inner complex object type.

Lets assume the following structure:

@DynamoDBTable(tableName = "Product")
public class Product {

    @DynamoDBHashKey
    @DynamoDBAutoGeneratedKey
    private String id;

    @DynamoDBFlattened
    private Supplier supplier;

}

@DynamoDBTable(tableName = "Supplier")
public class Supplier {

    @DynamoDBHashKey
    @DynamoDBAutoGeneratedKey
    private String id;

    private String name;

}

Now let's suppose I have the following supplier on ther Supplier database:

{
    "id": "1",
    "name": "Nick"
}

And the following product on Product database:

{
    "id": "1",
    "supplier": { "id": "1", "name": "Nick" }
}

What happens if I update the supplier on the Supplier database to look like this:

{
    "id": "1",
    "name": "John"
}

What happens to the Product registry? Does product with id 1 get its supplier name automatically updated to John? Or it stays Nick?

Upvotes: 0

Views: 1678

Answers (1)

Bjørn Vårdal
Bjørn Vårdal

Reputation: 174

No, there's no relation between the data in the two tables. The purpose of @DynamoDBFlattened is to allow you to use complex types in your code that are flattened into individual fields once stored in the DynamoDB table.

In your case specifically, there shouldn't be a Supplier table, as the data is stored in the Product table. It can only be retrieved through a product unless you use a secondary index to fetch suppliers.

Upvotes: 1

Related Questions