Error while using DynamoDB AWS SDK [No Mapping for Hash Key] because of naming convention

旧街凉风 提交于 2019-12-25 07:46:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!