3

Although, @DynamoDBTable annotation is there still getting exception when ever I am doing batchsave and also why IntelliJ inspection telling DynamoDBMapperConfig is deprecated.

Although, @DynamoDBTable annotation is there still getting exception when ever I am doing batchsave and also why IntelliJ inspection telling DynamoDBMapperConfig is deprecated.

object  TestDDbOperation{
  final val EMPLOYEE_TABLE_NAME = "TestAnytimepayEmployeeJobData"
  final val EMPLOYEE_ID_HASH_ATTRIBUTE = "employeeId"
  final val EMPLOYEE_JOB_DATA_LIST_ATTRIBUTE = "employeeJobDataList"
  final val LAST_UPDATE_TIME_ATTRIBUTE = "lastUpdatedTime"
}

@DynamoDBTable(tableName = TestDDbOperation.EMPLOYEE_TABLE_NAME)
class TestDDbOperation {
  import TestDDbOperation._

  @BeanProperty
  @DynamoDBHashKey(attributeName = EMPLOYEE_ID_HASH_ATTRIBUTE)
  var employeeId: String = _

  @BeanProperty
  @DynamoDBAttribute(attributeName = LAST_UPDATE_TIME_ATTRIBUTE)
  var lastUpdatedTime: Long = _
}

DDbOperation:

    def batchSaveInDDB[T](employeeJobDataList: ArrayList[T]): List[FailedBatch] =
     AWSSession.dynamoDBMapper.batchSave(employeeJobDataList, new 
     DynamoDBMapperConfig(DynamoDBMapperConfig.SaveBehavior.UPDATE))

2 Answers 2

0

I had the same issue with batchDelete. I could solved it calling to the batchWrite method like this:

dynamoDBMapper.batchWrite(Collections.emptyList(), objectsToDelete, config)

For batch save will be:

dynamoDBMapper.batchWrite(objectsToSave, Collections.emptyList(), config)
Sign up to request clarification or add additional context in comments.

Comments

0

This happens because you are passing List type to batchSave method which takes varargs:
public List<DynamoDBMapper.FailedBatch> batchSave(Object... objectsToSave)

To make it work you need to convert list to an array and add spread operator (:_*), which I believe in Scala would be:

AWSSession.dynamoDBMapper.batchSave(employeeJobDataList.toList:_*), new DynamoDBMapperConfig(DynamoDBMapperConfig.SaveBehavior.UPDATE))

unfortunately, batch save has no method with config parameter, so if you want to use it you have to call batchWrite directly with an empty list:
dynamoDBMapper.batchWrite(employeeJobDataList, Collections.emptyList(), config)

For more info take a look here:
How to pass Scala array into Scala vararg method?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.