我想仅使用Hashkey查询我的dynamoDB。 我的表(name = testTable)模式如下:
我的dynamoDBQueryExpression是:
None
我期待一个具有相同autoID的testTable对象列表。因为我是新手,如果我错了,请纠正我。
当我拨打String hashKey = "dummyHashKey";
testTable hashKeyValues = new testTable();
hashKeyValues.setAutoID(hashKey);
DynamoDBQueryExpression<testTable> queryExpression = new DynamoDBQueryExpression<testTable>();
queryExpression.withHashKeyValues(hashKeyValues);
//Assuming I have a dynamoDBMapper object mapper
List<testTable> docList = mapper.query(testTable.class, queryExpression);
电话时没有任何反应。
Vikdor在StackOverflow问题上引用评论 query using hashKey in dynamoDB
进一步修改:
我的确切QueryMethod:
mapper.query()
我的程序的堆栈跟踪:
调用方法来保存表中的对象:
public void queryFromRFIDocumentDetails(String hashKey){
System.out.println((new Throwable()).getStackTrace()[0].toString() + "***Enter***");
testTable hashKeyValues = new testTable();
hashKeyValues.setAutoID(hashKey);
System.out.println("AutoID for hashKeyValues " + hashKeyValues.getAutoID());
System.out.println("DocTYpe for hashKeyValues " + hashKeyValues.getDocType());
System.out.println("AlexandriaID for hashKeyValues " + hashKeyValues.getAlexandraiID());
DynamoDBQueryExpression<testTable> queryExpression = new DynamoDBQueryExpression<testTable>();
queryExpression.withHashKeyValues(hashKeyValues);
queryExpression.withConsistentRead(false);
System.out.println("calling mapper.query"); //nothing happens after this
List<testTable> docList = new ArrayList<testTable>();
docList = mapper.query(testTable.class, queryExpression);
for(int i=0; i<docList.size(); i++){
System.out.println("***iterating at retrieved index " + i);
System.out.println("AutoID for retrieved document " + docList.get(i).getAutoID());
System.out.println("DocTYpe for retrieved document " + docList.get(i).getDocType());
System.out.println("AlexandriaID for retrieved document " + docList.get(i).getAlexandraiID());
}
}
调用方法以autoID:
为基础查询表***iterating at index 0
[java] AutoID for document to be saved abc
[java] DocTYpe for document to be saved foo
[java] AlexandriaID for document to be saved id1
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:201)***Enter***
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:203)***Exit***
[java] ***iterating at index 1
[java] AutoID for document to be saved abc
[java] DocTYpe for document to be saved foo
[java] AlexandriaID for document to be saved id2
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:201)***Enter***
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:203)***Exit***
[java] ***iterating at index 2
[java] AutoID for document to be saved abc
[java] DocTYpe for document to be saved foo
[java] AlexandriaID for document to be saved id3
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:201)***Enter***
[java] com.amazon.sduservice.db.dynamoDB.saveInRFIDocumentDetails(dynamoDB.java:203)***Exit***
[java] hashKey is abc
桌面扫描操作输出:
[java] com.amazon.sduservice.db.dynamoDB.queryFromRFIDocumentDetails(dynamoDB.java:207)***Enter***
[java] AutoID for hashKeyValues abc
[java] DocTYpe for hashKeyValues null
[java] AlexandriaID for hashKeyValues null
[java] calling mapper.query
testTable类:
Scanning Table RFIDocumentDetails
[java] {docType={S: foo,}, autoID={S: abc,}, alexandriaID={S: id1,}}
[java] {docType={S: foo,}, autoID={S: abc,}, alexandriaID={S: id2,}}
[java] {docType={S: foo,}, autoID={S: abc,}, alexandriaID={S: id3,}}
[java] {docType={S: pdf,}, autoID={S: HashKey,}, alexandriaID={S: alexandriaID1,}}
[java] {docType={S: pdf,}, autoID={S: HashKey,}, alexandriaID={S: alexandriaID2,}}
[java] {docType={S: foo,}, autoID={S: asdf,}, alexandriaID={S: id1,}}
[java] {docType={S: foo,}, autoID={S: asdf,}, alexandriaID={S: id2,}}
[java] {docType={S: foo,}, autoID={S: foo,}, alexandriaID={S: id1,}}
[java] {docType={S: foo,}, autoID={S: foo,}, alexandriaID={S: id2,}}
[java] Scanning Table Finishes
答案 0 :(得分:1)
如上所述,问题似乎出现在getAlexandraiID声明中。
请更改方法名称,如下所述: -
发件人: - 强>
public String getAlexandraiID(){ return alexandriaID;}
要: - 强>
@DynamoDBRangeKey(attributeName = "alexandriaID")
public String getAlexandriaID() {
return alexandriaID;
}