“所提供的密钥元件不匹配模式”从AWS Android SDK中
问题描述:
林从AWS Android SDK中的指令之后的样品中, http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/getting-started-store-query-app-data.html 但是当我执行mapper.save()
方法,它总是抛出“所提供的密钥元件不匹配模式”从AWS Android SDK中
07-10 11:47:28.966: E/AndroidRuntime(2030):
com.amazonaws.AmazonServiceException: The provided key element does not
match the schema (Service: AmazonDynamoDBv2; Status Code: 400;
Error Code: ValidationException; Request ID:
这里是我的表:
和My Book型号代码:
package com.example.qingzhong.awssample.dbresources;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBAttribute;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBHashKey;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBIndexHashKey;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBIndexRangeKey;
import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBTable;
/**
* Created by qingzhong on 10/7/15.
*/
@DynamoDBTable(tableName = "Books")
public class Book {
private String title;
private String author;
private int price;
private String isbn;
private Boolean hardCover;
@DynamoDBIndexRangeKey(attributeName = "Title")
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@DynamoDBIndexHashKey(attributeName = "Author")
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
@DynamoDBAttribute(attributeName = "Price")
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
@DynamoDBHashKey(attributeName = "ISBN")
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
@DynamoDBAttribute(attributeName = "Hardcover")
public Boolean getHardCover() {
return hardCover;
}
public void setHardCover(Boolean hardCover) {
this.hardCover = hardCover;
}
}
和我的代码在MainActivity,只需使用mapper.save()方法,没什么奇特的:
我不知道哪里出了问题,因为所有需要的属性在Book.class增加,实际上进出口以下从AWS移动SDK
答
最后我工作的指示出来,从链接图片:
实际上是误导性的,如果你想使用ISBN作为代码散列键,你需要符合规范ify
1.选择Hash作为主键类型。 2.对于哈希属性名称,请确保已选中字符串并输入ISBN。点击继续。
http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/dynamodb_om.html
我的混乱清抱歉。我同意这是误导性的,我们会尽快更正文件。感谢您指出了这一点。 – WestonE
你非常欢迎;) – Qing
所以你改变了什么..? – jerbotron