如何在 DynamoDbTable 中存储相同的内部结构
How to store the same inner structure inside a DynamoDbTable
我有一个名为 Customer 的 class,里面有两个具有相同对象的字段。
@Value
@Builder
@DynamoDbImmutable(builder = Customer.CustomerBuilder.class)
public class Customer {
@Getter(onMethod_ = @DynamoDbPartitionKey)
String id;
@Getter(onMethod_ = {@DynamoDbFlatten,
@DynamoDbAttribute("phone")})
Phone phone;
@Getter(onMethod_ = {@DynamoDbFlatten,
@DynamoDbAttribute("HomePhone")})
Phone homePhone;
phone结构
@Value
@Builder
@DynamoDbImmutable(builder = Phone.PhoneBuilder.class)
public class Phone {
String number;
....
当我将项目放入 DynamoDB 时 table 它说
Caused by: java.lang.IllegalArgumentException: Attempt to add an attribute to a mapper that already has one with the same name. [Attribute name: number]
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.lambda$null(StaticImmutableTableSchema.java:184)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1085)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.lambda$new(StaticImmutableTableSchema.java:181)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.<init>(StaticImmutableTableSchema.java:179)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.<init>(StaticImmutableTableSchema.java:77)
我应该如何存储它,尝试为字段指定不同的名称,例如通过 DynamoDbAttribute,但没有多大帮助
您目前正在通过 @DynamoDbFlatten
扁平化 phone
和 homePhone
,这会将它们的组成属性(都有 number
)移动到 top-level 属性.您最终得到两个名为 number
的 top-level 属性,导致了冲突。
从两者中删除 @DynamoDbFlatten
并存储 phone
和 homePhone
,以便它们成为分层的。或者找到一些其他方法使这些属性名称唯一(例如,在属性级别重命名它们)。
我有一个名为 Customer 的 class,里面有两个具有相同对象的字段。
@Value
@Builder
@DynamoDbImmutable(builder = Customer.CustomerBuilder.class)
public class Customer {
@Getter(onMethod_ = @DynamoDbPartitionKey)
String id;
@Getter(onMethod_ = {@DynamoDbFlatten,
@DynamoDbAttribute("phone")})
Phone phone;
@Getter(onMethod_ = {@DynamoDbFlatten,
@DynamoDbAttribute("HomePhone")})
Phone homePhone;
phone结构
@Value
@Builder
@DynamoDbImmutable(builder = Phone.PhoneBuilder.class)
public class Phone {
String number;
....
当我将项目放入 DynamoDB 时 table 它说
Caused by: java.lang.IllegalArgumentException: Attempt to add an attribute to a mapper that already has one with the same name. [Attribute name: number]
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.lambda$null(StaticImmutableTableSchema.java:184)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1085)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.lambda$new(StaticImmutableTableSchema.java:181)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.<init>(StaticImmutableTableSchema.java:179)
at software.amazon.awssdk.enhanced.dynamodb.mapper.StaticImmutableTableSchema.<init>(StaticImmutableTableSchema.java:77)
我应该如何存储它,尝试为字段指定不同的名称,例如通过 DynamoDbAttribute,但没有多大帮助
您目前正在通过 @DynamoDbFlatten
扁平化 phone
和 homePhone
,这会将它们的组成属性(都有 number
)移动到 top-level 属性.您最终得到两个名为 number
的 top-level 属性,导致了冲突。
从两者中删除 @DynamoDbFlatten
并存储 phone
和 homePhone
,以便它们成为分层的。或者找到一些其他方法使这些属性名称唯一(例如,在属性级别重命名它们)。