gpt4 book ai didi

spring - 写入 Dynamodb 表工作正常,但读取会引发 DynamoDBMappingException

转载 作者:行者123 更新时间:2023-12-03 19:53:16 24 4
gpt4 key购买 nike

正在执行 orderRequestDao.save(new OrderRequest("5000", "body"));成功地在 Dynamo 中放置了一个记录。任何读取返回的尝试:

[Request processing failed; nested exception is com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMappingException:
could not invoke null on class
com.cfa.fulfillmentApi.model.OrderRequest
with value 100 of type class java.lang.String] with root cause
(id 为 100 的记录存在)
我正在使用以下 jars (aws.sdk.version: 1.11.86):
    <dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>${aws.sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>${aws.sdk.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>${aws.sdk.version}</version>
</dependency>
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>4.4.1</version>
</dependency>
DynamoDb 配置:
主分区键: id (String)道:
@EnableScan
public interface OrderRequestDao extends CrudRepository<OrderRequest, String> {
OrderRequest findOne(String s);
OrderRequest save(OrderRequest or);
}
域对象:
@DynamoDBTable(tableName = "dev_transx")
public class OrderRequest {

private String id;
private String body;

public OrderRequest(String id, String body) {
this.id = id;
this.body = body;
}

public OrderRequest() {}

@DynamoDBHashKey
public String getId()
{
return id;
}

@DynamoDBAttribute
public String getBody()
{
return body;
}

public void setBody(String body) {
this.body = body;
}

@Override
public String toString() {
return String.format(
"Customer[id=%d, body='%s']",
id, body);
}

@Override
public int hashCode() {
return id.hashCode();
}

}
我已经尝试了域类中 id 的几乎所有数据类型,但没有运气。

最佳答案

我删除了 aws-java-sdk-dynamodb因为它已经在 spring-data-dynamodb
最重要的是,我在域类中为 ID 添加了一个 setter。

关于spring - 写入 Dynamodb 表工作正常,但读取会引发 DynamoDBMappingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41990190/

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