简体   繁体   中英

dynamoDB Transaction Manager

I have a scenario where i have to execute multiple queries (delete and add) so i am using Transaction Library of dynamoDB but i am getting serialisation error. I referred this url as an example http://aws.amazon.com/blogs/aws/dynamodb-transaction-library/

Below is my code:

DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
PaginatedScanList<FinanceIndex> financeIndex = mapper.scan(FinanceIndex.class, scanExpression);
String index, index1 = null;

AWSCredentials credentials = Application.getCredentials();
AmazonDynamoDB client = new AmazonDynamoDBClient(credentials);
TransactionManager manager = new TransactionManager(client, "Transactions", "TransactionImages");
TransactionManager.verifyOrCreateTransactionTable(client, "Transactions", new Long(10) , new Long(10), new Long(1060));
TransactionManager.verifyOrCreateTransactionImagesTable(client, "TransactionImages", new Long(10), new Long(10), new Long(1060));
for (FinanceIndex financeID : financeIndex) {
  index1 = financeID.getID();
  Transaction t1 = manager.newTransaction();
  Map<String, AttributeValue> reply1 = new HashMap<String, AttributeValue>();
  reply1.put("id", new AttributeValue(index1));
  t1.deleteItem(new DeleteItemRequest().withTableName("FinanceIndex").withKey(reply1));

  //mapper.delete(financeID);
  int id = Integer.valueOf(index1);
  id = id + 1;
  index = String.valueOf(id);
  financeID.setID(index);
  //mapper.save(financeID);
  Map<String, AttributeValue> reply2 = new HashMap<String, AttributeValue>();
  reply2.put("id", new AttributeValue(financeID.getID()));
  t1.putItem((new PutItemRequest().withTableName("FinanceIndex").withItem(reply2)));
  t1.commit();
}
return index1;

I get below error:

com.amazonaws.services.dynamodbv2.transactions.exceptions.TransactionAssertionException: d1c3bb93-e9b7-4052-b328-b357ab412a3a - Failed to serialize request com.amazonaws.services.dynamodbv2.transactions.Request$DeleteItem@4dcdd700 com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class com.amazonaws.event.ProgressListener$1 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.amazonaws.services.dynamodbv2.transactions.DeleteItem["request"]->com.amazonaws.services.dynamodbv2.model.DeleteItemRequest["generalProgressListener"])

Can anyone tell me what am i doing wrong? Thanks in advance.

I use this library too, and similar problem occur and researched.

This library is not maintenance for AWS Java SDK now. So this library correct working until AWS Java SDK 1.7.6.

Because over 1.7.7 have new feature about conditional expression. http://aws.amazon.com/releasenotes/Java/2402335129612731

Dynamodb-transaction library is not follow this feature and can't create correct query. So can't using 1.7.7 added future and dynamodb-transaction together.

Over 1.7.7 library have so nice future, like conditional atomic counter. But transaction function really important also..

Now only that can choose to us using transaction library with AWS Java SDK 1.7.6 or without transaction library with newest AWS Java SDK.

good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM