0

I'm new to DynamoDB and am having some trouble loading data from my database with my Java code. I can see from the DDB console that I'm successfully storing data in tables and reading it in through scan. But if I try to use load, things fail.

Here's what I'm doing:

I'd like to read all of the items in a table, so I use this code

DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    
List<SericonNoSQLdbRecord> scanResult = dynamoMapper.scan(tableName2Class(tableName), 
                                                          scanExpression);

for (SericonNoSQLdbRecord record : scanResult) 
  {
  record.printJSON();
  }

This works beautifully and each item is printed out. The fact that this works tells me that the underlying class that I'm storing is properly annotated.

Later on, I want to read a single item. For that I use this code

Object ob = dynamoMapper.load(tableName2Class(tableName), 
                              primaryIndex);  // this is the HashKey

When this code is executed I can see that the empty constructor for my class is called (as can be expected) followed by a call to set the HashKey. After that, I expect that setters for the attributes will be called but this doesn't happen. Instead, load simply returns null. I am catching errors, and none seem to be thrown.

I know that load returns null if no item is found. But the fact that my HashKey's setter is called suggests that something was found.

Any ideas on what could be going wrong here. Any ideas on how to further debug this problem?

Sander Smith
  • 1,371
  • 4
  • 20
  • 30

1 Answers1

0

First thing I would do is make sure the value you pass into load() is what you expect, often times you think you're passing in something but it's actually obscured in some way.

If it looks good, then make the same request using the CLI, that way you can know if something is wrong with your java implementation or if there's something wrong with your parameters.

Add plenty of log lines in your code, use the debugger.

Enable http wire logging and you can see what's being requested and responded.

Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31