Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One-to-many in DynamoDB with Java Object Persistence Model

Is possible to create a relationship between two tables using DynamoDB Java Persistence Model?

I have the follow relationship of One Post to Many Comments

@DynamoDBTable(tableName="Post_MyApp")
public class Post {

private String id;
private String title;
private Set <Comment> comments;
//... Getters and setters and dynamo annotations
}

I have a separated table of comments, that Comment is another dynamo table/entity. My idea is create a table of post_comments like in SQL with all the comments of a post. This is the right way to do this with Dynamo or there is another way to do it better?

like image 771
Deivid Martins Avatar asked Aug 14 '26 19:08

Deivid Martins


1 Answers

One post to many comments. You just need the following tables: 1. Post table: post-id (Hash Key), 2. Comment table: post-id (Hash Key), comment-id (Range Key)

To get all the comment for a post, you query the comment table by just giving the HashKey (post-id).

On Java side, you will have 2 classes (Post, Comments) mapped with the Dynamo DB Mapper.

DynamoDBMapper (AWS SDK for Java - 1.7.1) : http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodb/datamodeling/DynamoDBMapper.html

like image 129
Sony Kadavan Avatar answered Aug 17 '26 08:08

Sony Kadavan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!