How do I use DynamoDBAutoGeneratedKey to give me an auto generated key?

老子叫甜甜 提交于 2021-02-08 15:11:16

问题


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?


回答1:


Found easy answer.

String uniqueID = UUID.randomUUID().toString();

Screw using DynamoDBAutoGeneratedKey, sounds like a headache.




回答2:


@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;
    }
...


来源:https://stackoverflow.com/questions/37912236/how-do-i-use-dynamodbautogeneratedkey-to-give-me-an-auto-generated-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!