问题
While using AWS JAva SDK, for defining DynamoDBHashKey we @DynamoDBHashKey annotation.
Strangely if i use annotation as below
@DynamoDBHashKey
String Abc
instead of
@DynamoDBHashKey
String abc
this gives me an error, no mapping for HASH key [junit] at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperTableModel.hashKey(DynamoDBMapperTableModel.java:119) [junit] at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperTableModel$Builder.build(DynamoDBMapperTableModel.java:449) [junit] at com.amazonaws.services.dynamodbv2.datamodeling.StandardModelFactories$StandardTableFactory.getTable(StandardModelFactories.java:104) [junit] at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.getTableModel(DynamoDBMapper.java:393) [junit] at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.generateCreateTableRequest(DynamoDBMapper.java:2148) [junit] at com.amazonaws.services.dynamodbv2.datamodeling.AbstractDynamoDBMapper.generateCreateTableRequest(AbstractDynamoDBMapper.java:319)
I am unable to understand why does variable naming convention plays a role in failure Any Idea?
回答1:
Introspection magic does not appear to be working in this case. Force the attribute name with the parameter attributeName
.
@DynamoDBTable(tableName="Books")
public static class Book {
private String Abc;
@DynamoDBHashKey(attributeName="Abc")
public int getAbc() {
return Abc;
}
}
来源:https://stackoverflow.com/questions/42802020/error-while-using-dynamodb-aws-sdk-no-mapping-for-hash-key-because-of-naming-c