Android AWS DynamoDB"没有哈希密钥条件"

时间:2015-07-10 19:13:10

标签: android amazon-web-services amazon-dynamodb

我有一个包含一些数据的DynamoDB表。有一个#34; class_id"的哈希键。以及" message_timestamp"的范围键。

在我的Android代码中,我试图查询比最后收到的消息更新的消息。

int lastMessageTimestamp = GetNewestTimestamp();

DynamoChatData messagesToFind = new DynamoChatData();
Log.i(TAG,String.valueOf(class_id));
messagesToFind.SetClassId(class_id); // Set to 2 in the debugger at runtime

Condition rangeKeyCondition = new Condition();
rangeKeyCondition.withComparisonOperator(ComparisonOperator.GT.toString());

AttributeValue attributeValue = new AttributeValue();
attributeValue.withN(String.valueOf(lastMessageTimestamp));

rangeKeyCondition.withAttributeValueList(attributeValue);

DynamoDBQueryExpression<DynamoChatData> query = new DynamoDBQueryExpression<>();
query.withHashKeyValues(messagesToFind);
query.withRangeKeyCondition("message_timestamp", rangeKeyCondition);
query.withConsistentRead(false);

PaginatedQueryList result = objectMapper.query(DynamoChatData.class, query);

DynamoChatData类:

@DynamoDBTable(tableName = "scriyb_chat")
public class DynamoChatData {
    private int class_id;
    private int message_timestamp;
    private String user_name;
    private String user_full_name;
    private String message_content;
    private int message_visible;
    private int message_underage;

    @DynamoDBRangeKey(attributeName = "message_timestamp")
    public int GetMessageTimestamp(){
        return message_timestamp;
    }

    public void SetMessageTimestamp(int _message_timestamp){
        message_timestamp = _message_timestamp;
    }

    @DynamoDBHashKey(attributeName = "class_id")
    public int GetClassId(){
        return class_id;
    }

    public void SetClassId(int _class_id){
        class_id = _class_id;
    }

    @DynamoDBAttribute(attributeName = "user_name")
    public String GetUsername(){
        return user_name;
    }

    public void SetUsername(String _user_name){
        user_name = _user_name;
    }

    @DynamoDBAttribute(attributeName = "user_full_name")
    public String GetUserFullName(){
        return user_full_name;
    }

    public void SetUserFullName(String _user_full_name){
        user_full_name = _user_full_name;
    }

    @DynamoDBAttribute(attributeName = "message_content")
    public String GetMessageContent(){
        return message_content;
    }

    public void SetMessageContent(String _message_content){
        message_content = _message_content;
    }

    @DynamoDBAttribute(attributeName = "message_visible")
    public int GetMessageVisible(){
        return message_visible;
    }

    public void SetMessageVisible(int _message_visible){
        message_visible = _message_visible;
    }

    @DynamoDBAttribute(attributeName = "message_underage")
    public int GetMessageUnderage(){
        return message_underage;
    }

    public void SetMessageUnderage(int _message_underage){
        message_underage = _message_underage;
    }
}

我按照here概述的基本示例阅读了本网站上的一些帖子。不知道为什么我得到了

java.lang.IllegalArgumentException: Illegal query expression: No hash key condition is found in the query

错误。

感谢任何见解。

1 个答案:

答案 0 :(得分:0)

尝试使用重构getter / setter名称,以便它们以标准Java约定的小写字母开头。我相信mapper会将getter视为以“get”开头的方法,而且我认为它们是因为它们以国会大厦G开头而缺少你的。

让我知道这是否可以解决您的问题! 韦斯顿