dynamodbmapper batchdelete方法在Java中不起作用
您好,我正在使用以下依赖性来读取/写作对Spring Boot中的DynamoDB。 在内部,此API调用DynamoDBMapper执行其任何操作。 DynamoDbmapper是AWS SDK。 我相信,DynampMapper批次delete Call in AWS SDK
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>5.1.0</version>
</dependency>
java.lang.reflect.InaccessibleObjectException: Unable to make final void java.lang.Throwable.setCause(java.lang.Throwable) accessible: module java.base does not "opens java.lang" to unnamed module @1b083826
调用代码看起来像
List<Matchup> matchups = (List<Matchup>) matchupRepository.findAll();
DynamoDBMapper dynamoDBMapper = new DynamoDBMapper(amazonDynamoDBClient);
try {
dynamoDBMapper.batchDelete(matchups);
}
catch(Exception e) {
log.error(e.toString());
}
实体类的样子,因此
@Data
@NoArgsConstructor
@AllArgsConstructor
@DynamoDBTable(tableName = "Sportsbook")
public class Matchup {
@DynamoDBAttribute(attributeName = "MatchupId")
private String matchupId;
@DynamoDBAttribute(attributeName = "SportsKey")
private String sportsKey;
@DynamoDBAttribute(attributeName = "CommenceTime")
private String commenceTime;
@DynamoDBAttribute(attributeName = "HomeTeam")
private String homeTeam;
@DynamoDBAttribute(attributeName = "AwayTeam")
private String awayTeam;
@DynamoDBHashKey(attributeName = "PK")
public String getPK() {
return "MATCHUP#"+ matchupId;
}
public void setPK(String pk) {
//do nothing
}
}
我注意到除了BatchDelete之外,DynamoDBMapper工作的所有其他方法。它具有以下方法签名
List<FailedBatch> batchDelete(Iterable<? extends Object> var1);
Hello I am using the following dependency for reading/writing to DynamoDB in spring boot. Internally this api calls DynamoDBMapper for performing any of its operations. DynamoDBMapper is apart of the AWS SDK. I BELIEVE THERE IS AN ISSUE WITH THE DYNAMODBMAPPER BATCH DELETE CALL IN AWS SDK
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>5.1.0</version>
</dependency>
However, when I invoke the DynamoDBMapper batchDelete method I get the following error
java.lang.reflect.InaccessibleObjectException: Unable to make final void java.lang.Throwable.setCause(java.lang.Throwable) accessible: module java.base does not "opens java.lang" to unnamed module @1b083826
Here is what the invoking code looks like
List<Matchup> matchups = (List<Matchup>) matchupRepository.findAll();
DynamoDBMapper dynamoDBMapper = new DynamoDBMapper(amazonDynamoDBClient);
try {
dynamoDBMapper.batchDelete(matchups);
}
catch(Exception e) {
log.error(e.toString());
}
The entity class looks like so
@Data
@NoArgsConstructor
@AllArgsConstructor
@DynamoDBTable(tableName = "Sportsbook")
public class Matchup {
@DynamoDBAttribute(attributeName = "MatchupId")
private String matchupId;
@DynamoDBAttribute(attributeName = "SportsKey")
private String sportsKey;
@DynamoDBAttribute(attributeName = "CommenceTime")
private String commenceTime;
@DynamoDBAttribute(attributeName = "HomeTeam")
private String homeTeam;
@DynamoDBAttribute(attributeName = "AwayTeam")
private String awayTeam;
@DynamoDBHashKey(attributeName = "PK")
public String getPK() {
return "MATCHUP#"+ matchupId;
}
public void setPK(String pk) {
//do nothing
}
}
I noticed all other methods of DynamoDBMapper work except batchDelete. It has the following method signature
List<FailedBatch> batchDelete(Iterable<? extends Object> var1);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有使用最新的AWS Java API执行此任务。 dynamodbmapper 是Java V1的 AWS SDK的一部分,不再被视为最佳实践 。这是DynamoDBMAPPER,它是V1 Dev指南的一部分=“ nofollow noreferrer”> https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-dynamodb-items.htmls.html
Amazon States:
Java 2.x的AWS SDK是版本1.x代码库的主要重写。它建在Java 8+之上,并添加了几个经常要求的功能。其中包括对非阻滞I/O的支持以及在运行时插入其他HTTP实现的能力。
执行此用例如 aws java v2 dev指南:
https://docs.aws.aws.amazon.com/sdk-for-java/latest/latest/deeverice-guide-guide/dynamodb-enhanced-client .html
这是一个代码示例,使用增强的客户端显示H OW ow 。首先 - 假设您有一个带有此数据的客户表,并且要删除批处理记录。
这是增强端客户端的完整代码示例。
More information here:
https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/DynamoDbEnhancedClient.html#batchWriteItem-software.amazon.awssdk 。
=“ https://i.sstatic.net/sc7yr.png” alt =“在此处输入图像说明”>
最后,您可以找到 customer class class,pom file等在 。
You are NOT using the most recent AWS Java API to perform this task. The DynamoDBMapper is part of AWS SDK for Java V1 and no longer considered best practice. Here is the DynamoDBMapper that is part of the V1 DEV Guide https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-dynamodb-items.html
Amazon States:
The AWS SDK for Java 2.x is a major rewrite of the version 1.x code base. It’s built on top of Java 8+ and adds several frequently requested features. These include support for non-blocking I/O and the ability to plug in a different HTTP implementation at run time.
To perform this use case, upgrade from AWS SDK for Java V1 to V2 and use and the Enhanced Client as explained in the AWS Java V2 DEV Guide:
https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/dynamodb-enhanced-client.html
Here is a code example that shows HOW TO Delete batch items using the Enhanced Client. First - assume you have a Customer table with this data and you want to delete batch records.
Here is the full code example with the Enhanced Client.
More information here:
https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/DynamoDbEnhancedClient.html#batchWriteItem-software.amazon.awssdk.enhanced.dynamodb.model.BatchWriteItemEnhancedRequest-
Now we are left with these items:
Finally, you can find the Customer class, the POM file, etc in AWS Java V2 Github here.