question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DynamoDB Enhanced Client Polymorphic Types

See original GitHub issue

We should support reading/writing base types using the DynamoDB Enhanced Client.

Potential syntax/example (not yet implemented):

@DynamoDbBean
@DynamoDbSubtypes({Employee.class, Customer.class})
public abstract class Person {
    @DynamoDBHashKey
    private long id;
    private String name;
}

@DynamoDbBean
private class Employee extends Person {
}

@DynamoDbBean
private class Customer extends Person {
}

DynamoDbEnhancedClient client = DynamoDbEnhancedClient.create();
DynamoDbTable<Person> people = client.table("people", TableSchema.fromBean(Person.class));

Employee bob = new Employee();
bob.setId(1);
bob.setName("Bob the Builder");

Customer lfh = new Customer();
lfh.setId(2);
lfh.setName("Low Flying Hawk");

people.putItem(bob);
people.putItem(lfh);

assertThat(people.getItem(Key.builder().partitionValue(1).build())).isInstanceOf(Employee.class);
assertThat(people.getItem(Key.builder().partitionValue(2).build())).isInstanceOf(Customer.class);

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:39
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

7reactions
bmaizelscommented, Nov 19, 2021

For anyone tracking this issue, I have created a PR with an implementation that I hope addresses the needs identified here. It will probably be at least a couple of weeks before this gets final approval and makes it into the release, so it would be extremely valuable if people could try it out and see if there are any rough edges or improvements I could make before it becomes difficult to change it after release. It’s a complex change, so lots of scope for not getting things quite right. Instructions on how to declare subtypes are in the new README.md file in the dynamodb-enhanced module under the section titled ‘Using subtypes…’. https://github.com/aws/aws-sdk-java-v2/pull/2861

7reactions
gakinsoncommented, Aug 18, 2020

This would be super useful!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the DynamoDB Enhanced Client in the AWS SDK for ...
It offers a straightforward way to map client-side classes to DynamoDB tables. You define the relationships between tables and their corresponding model classes...
Read more >
Querying an Item Collection of Distinct Types Java
Does anyone have suggestions for dealing with a query on an item collection? Example: an item collection which contains a Customer, an Order, ......
Read more >
EnhancedAttributeValue (AWS SDK for Java - 2.18.35)
software.amazon.awssdk.enhanced.dynamodb.internal.converter.attribute. ... provided that exposes a polymorphic way of converting a value into another type.
Read more >
DynamoDBMapper support for inheritance - Stack Overflow
Let me know if this is supported. Or any workarounds for storing polymorphic types from Java in DynamoDb. Thanks in advance,.
Read more >
How to model one-to-many relationships in DynamoDB
Denormalization by using a complex attribute; Denormalization by duplicating data; Composite primary key + the Query API action; Secondary index ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found