Qing
Qing

Reputation: 1411

"the provided key element does not match the schema" in the sample from AWS Android SDK

Im following the instruction from AWS Android SDK, http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/getting-started-store-query-app-data.html but when I perform the mapper.save() method, it always throws

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:

enter image description here

here's my table :

enter image description here

and my Book Model code:

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;
    }
}

and my code in the MainActivity , just use the mapper.save() method,nothing fancy:

enter image description here

I don't know what goes wrong, since all the required attributes are added in the Book.class, and actually Im following the instruction from AWS Mobile SDK

enter image description here

Upvotes: 3

Views: 20993

Answers (1)

Qing
Qing

Reputation: 1411

Finally I worked it out, the Picture from the link:

http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/getting-started-store-query-app-data.html

is actually misleading, if you want to use the ISBN as hash key in the code, you need to specify

1.Select Hash as the primary key type. 2.For the hash attribute name, ensure that String is selected and enter ISBN. Click Continue.

http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/dynamodb_om.html

Upvotes: 2

Related Questions