gpt4 book ai didi

java - 使用映射器在 DynamoDB 上保存时出现 ValidationException

转载 作者:行者123 更新时间:2023-11-30 10:46:40 25 4
gpt4 key购买 nike

我在使用 DynamoDBMapper 将新项目 (WCode) 保存到 DynamoDB 实例时遇到此错误:

Exception in thread "Thread-1" com.amazonaws.AmazonServiceException: The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 4OOMKU7NS1VD19EN988SUUM3U7VV4KQNSO5AEMVJF66Q9ASUAAJG)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1369)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:913)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:631)
at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:400)
at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:362)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:311)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:1966)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.updateItem(AmazonDynamoDBClient.java:1780)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$SaveObjectHandler.doUpdateItem(DynamoDBMapper.java:1110)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$2.executeLowLevelRequest(DynamoDBMapper.java:806)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper$SaveObjectHandler.execute(DynamoDBMapper.java:989)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:835)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:669)
at com.wkt.cdmng.MessageAnalyzer.storeCode(MessageAnalyzer.java:220)
at com.wkt.cdmng.MessageAnalyzer.run(MessageAnalyzer.java:156)
at java.lang.Thread.run(Thread.java:745)

我猜它与 WCode 类的关键属性有关,但我无法真正理解是哪一个以及如何搜索其他详细信息问题。

以下是WCode模型类,所有属性名都正确报出:

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIndexHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
import java.util.Date;

@DynamoDBTable(tableName = "CODES_DEV")
public class WCode {
private String id;
private String code;
private String extra;

@DynamoDBHashKey(attributeName = "ID")
public String getId() {return id;}
public void setId(String code) {id = "0|" + code + "|" + String.valueOf(new Date().getTime());}

@DynamoDBIndexHashKey(globalSecondaryIndexName = "CD-index", attributeName = "CD")
public String getCode() {return code;}
public void setCode(String code) {this.code = code;}

@DynamoDBAttribute(attributeName = "EX")
public String getExtra() {return extra;}
public void setExtra(String extra) {this.extra = extra;}
}

这是我用来存储项目的方法(storeCode):

private void storeCode(String code) {
DynamoDBMapper mapper = awsDynamo.getMapper(); // singleton class I use to connect to DynamoDB
WCode tmpCode = new WCode();
tmpCode.setId(code);
tmpCode.setCode(code);
tmpCode.setExtra("");
mapper.save(tmpCode);
}

我正在使用 aws-java-sdk-dynamodbaws-java-sdk-sqs(后者用于项目的另一部分)版本 1.10.58.

有人可以指出可能的解决方案或建议吗?

非常感谢!

最佳答案

我遇到了同样的问题。我已经解决了使用 batchSave 函数而不是保存

mapper.batchSave(Arrays.asList(tmpCode));

对我有用

关于java - 使用映射器在 DynamoDB 上保存时出现 ValidationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36428203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com