You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过@DynamoDbAutoGeneratedUuid获取AWS DynamoDB增强客户端生成的UUID?

AWS DynamoDB增强客户端自动生成UUID的注意事项

AWS DynamoDB增强客户端提供了AutoGeneratedUuidExtension,它会在putItem操作期间自动生成UUID。如果将这个UUID用作分区键,你必须获取新生成的值,否则后续无法通过getItem检索到对应数据。

实体类定义示例

@DynamoDbBean
public class Example {

    private String uuid;

    @DynamoDbPartitionKey
    @DynamoDbAutoGeneratedUuid
    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }
}

关键注意点:putItem不会更新传入的实体对象

putItem方法为void返回类型,它不会把自动生成的UUID回写到传入的实体实例中:

@Test
void newOfferShouldHaveUuidGenerated() {
    Example example = new Example();
    table.putItem(example); // putItem无返回值
    assertThat(example.getUuid()).isNotNull(); // 此断言会失败,因为example的uuid仍为null
}

内容的提问来源于stack exchange,提问作者timomeinen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 13:52:02