键上的条件数无效

j2qf4p5b  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(222)

当我试图在dynamodb中插入一个记录时,我得到了下面的错误。我正在使用SpringBoot和SpringDataDynamodB
密钥上的条件数无效(服务:amazondynamodbv2;状态码:400;错误代码:validationexception
表创建脚本:
aws dynamodb create table--表名partner\u signup--属性定义attributename=partner\u id,attributetype=s attributename=partner\u type,attributetype=s--密钥架构attributename=partner\u id,keytype=hash attributename=partner\u type,keytype=range--配置吞吐量readcapacityunits=1,writecapacityunits=1—端点urlhttp://localhost:8181

@DynamoDBTable(tableName = "partner_signup")

public class PartnerSignup {

    @Id
    @DynamoDBIgnore
    private ProductSignupId productSignupId;

    private String partnerId;
    private String partnerType;
    private String partnerName;

    public ProductSignupId getProductSignupId() {
        return productSignupId;
    }

    public void setProductSignupId(ProductSignupId productSignupId) {
        this.productSignupId = productSignupId;
    }

    @DynamoDBHashKey(attributeName = "partner_id")
    //@DynamoDBAutoGeneratedKey
    public String getPartnerId() {
        return productSignupId != null ? productSignupId.getPartnerId() : null;
    }
    public void setPartnerId(String partnerId) {
        this.partnerId = partnerId;
    }

    @DynamoDBAttribute(attributeName = "partner_type")
    //@DynamoDBRangeKey(attributeName = "partner_type")
    public String getPartnerType() {
        return productSignupId != null ? productSignupId.getPartnerType() : null;
    }
    public void setPartnerType(String partnerType) {
        this.partnerType = partnerType;
        if (productSignupId == null) {
            productSignupId = new ProductSignupId();
        }
        productSignupId.setPartnerType(partnerType);
    }

    @DynamoDBAttribute
    public String getPartnerName() {
        return partnerName;
    }
    public void setPartnerName(String partnerName) {
        this.partnerName = partnerName;
    }

}

@DynamoDBDocument

public class ProductSignupId {

    private String partnerId;
    private String partnerType;

    public ProductSignupId(String partnerId, String partnerType) {
        this.partnerId = partnerId;
        this.partnerType = partnerType;
    }

    public ProductSignupId() {
    }

    @DynamoDBHashKey(attributeName = "partner_id")
    public String getPartnerId() {
        return partnerId;
    }
    public void setPartnerId(String partnerId) {
        this.partnerId = partnerId;
    }

    @DynamoDBRangeKey(attributeName = "partner_type")
    public String getPartnerType() {
        return partnerType;
    }
    public void setPartnerType(String partnerType) {
        this.partnerType = partnerType;
    }
}

@Repository
@EnableScan

public interface PartnerSignupRepository extends CrudRepository<PartnerSignup, ProductSignupId> {
}

@PostMapping("/partners")
public PartnerSignup createPartner(@RequestBody PartnerSignupVO partnerSignupVO) {
    UUID key = UUID.randomUUID();
    PartnerSignup newPartnerSignup = new PartnerSignup();
    ProductSignupId id = new ProductSignupId(key.toString(),partnerSignupVO.getPartnerType());
    newPartnerSignup.setProductSignupId(id);
    newPartnerSignup.setPartnerName(partnerSignupVO.getPartnerName());
    repository.save(newPartnerSignup);
    return newPartnerSignup;
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题