I need to use DynamoDBAutoGeneratedKey from the AWS SDK to give me a random key(of type String) that I can then use to do something. I can't find any examples online of doing this, and while it seems like it should be relatively straightforward I am really struggling to get this working. Can anyone link me to an example of this being used?
DynamoDB does not support auto-incrementing IDs for items. They can be a performance bottleneck at scale, and most workloads are better off with UUIDs anyway. However, there are use cases where auto-incrementing integers are required.
DynamoDBDocument. Indicates that a class can be serialized as an Amazon DynamoDB document. For example, suppose that you wanted to map a JSON document to a DynamoDB attribute of type Map ( M ). The following code example defines an item containing a nested attribute (Pictures) of type Map.
The DynamoDBMapper class is the entry point to Amazon DynamoDB. It provides access to a DynamoDB endpoint and enables you to access your data in various tables. It also enables you to perform various create, read, update, and delete (CRUD) operations on items, and run queries and scans against tables.
Annotation Type DynamoDBIndexHashKeyAnnotation for marking a property in a class as the attribute to be used as the hash key for one or more global secondary indexes on a DynamoDB table. Applied to the getter method or the class field for the index hash key property.
Found easy answer.
String uniqueID = UUID.randomUUID().toString();
Screw using DynamoDBAutoGeneratedKey
, sounds like a headache.
@DynamoDBTable( tableName = "Details")
public class Details
{
@DynamoDBGeneratedUuid( DynamoDBAutoGenerateStrategy.CREATE )
private UUID id;
....
@DynamoDBHashKey(attributeName = "id")
@DynamoDBAutoGeneratedKey
public UUID getId()
{
return id;
}
// also you need to add the setter otherwise you will get an exception
public void setId(UUID id)
{
this.id = id;
}
...
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