How do I dynamically change the table accessed using DynamoDB's Java Mapper?
<p>I have a few DynamoDB tables, all of which have entries of the same structure. I want to create a single POJO to represent all of these entries and then use DynamoDB's Mapper API to load and save those objects.</p>
<p>The problem is that the API requires the annotation <code>@DynamoDBTable</code> on my POJO. This is a compile-time annotation requires a table name parameter and so would preclude me using the POJO in a dynamic manner. <a href="http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/datamodeling/DynamoDBMapperConfig.html" rel="noreferrer">DynamoDBMapperConfig</a> seems intended to allow just such dynamic behavior changes. Unfortunately, it is not working for me: I get a client-side DDB error saying that my POJO fails validation because of the empty string I put in the annotation.</p>
<p>I have looked repeatedly for why my DynamoDBMapperConfig is not being respected but can't find anything. My code is below, stripped down to the essentials:</p>
<p>My POJO:</p>
<pre><code>@DynamoDBTable(tableName = &quot;&quot;) // table name must be overridden on each call
public class TableEntry {
    . . .
}
</code></pre>
<p>My client:</p>
<pre><code>public class MyMapper {
    private final DynamoDBMapper mapper;
    private final DynamoDBMapperConfig configs;

    public MyMapper(String tableName) {
        AmazonDynamoDBClient client = . . .;
        mapper = new DynamoDBMapper(client);
        configs = new DynamoDBMapperConfig.Builder()
            .withTableNameOverride(TableNameOverride.withTableNameReplacement(tableName))
            .build();
    }

    . . .

    public void getEntry(String key) {
        return mapper.load(TableEntry.class, key, configs);
    }
}
</code></pre>
<p>When I run my code (substantially similar to what I have pasted here), I get the following message:</p>
<pre><code>2 validation errors detected: Value '' at 'tableName' failed to satisfy constraint: . . .
</code></pre>
<p>It goes on to say that (1) the table name is too short and (2) the table name doesn't match their regex pattern.</p>
<p>Any suggestions why my dynamically-named tables won't work with the DynamoDB Mapper API? Documentation references are much appreciated.</p>
<p>[I have found where the DynamoDBMapper <a href="https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-dynamodb/src/main/java/com/amazonaws/services/dynamodbv2/datamodeling/DynamoDBMapper.java#L590-L606" rel="noreferrer">retrieves the table name</a> but I haven't found any clues in there yet.]</p>