Anderology
Anderology

Reputation: 145

the provided key element does not match the schema - java

Not sure what the issue is here.This is my database on Amazon DynamoDb. I keep getting the issue of the provided key element does not match the schema.Ive done debuggind and Im sure all of the values are set, but not sure why this issue is coming up. Am I missing something?

enter image description here

This is the snippet of code where I actually try to add into the db

final Job job = new Job();
job.setDescription(txtDescription.getText().toString());
job.setType("Job entry");
job.setPrice(500);
job.setDate((new Date()).getTime());
job.setId("1");
job.setPosterID("poster");
Thread thread = new Thread(new Runnable(){
    @Override
    public void run() {
        try {
            DynamoDBMapper mapper = new DynamoDBMapper(ActivityMain.getAWSClient(getActivity()));
            mapper.save(job);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
});
thread.start();

Upvotes: 0

Views: 6690

Answers (2)

Gilad Levinson
Gilad Levinson

Reputation: 234

pay attention to the @DynamoDBHashKey and @DynamoDBAttribute in the object class. don't confuse between them .the first is for the key of the schema, and the second is for the regular attributes. even if you try to set only the key and don't use the other attributes,and then try to upload it to dynamodb, you will get an exception. of course it's relevant to the other "@" tags you can attach to the attributes.

Upvotes: 2

b-s-d
b-s-d

Reputation: 5143

This is most likely a mismatch between your data model and the actual table in DynamoDB. Make sure that the key defined in your 'Job' class (partition key and optionally sort key) matches the exact name and type of the table in DynamoDB (defined in your class by the @DynamoDBTable attribute). For example, if you executed the save operation using the data model below, and the table ProductCatalog had a partition key Id of type string, DynamoDB would generate the same exception as the data model defines the key as Integer:

@DynamoDBTable(tableName="ProductCatalog")
public static class CatalogItem {
   private Integer id;
   private String title;

   //Partition key
   @DynamoDBHashKey(attributeName="Id")
   public Integer getId() { return id; }
   public void setId(Integer id) { this.id = id; }

  @DynamoDBAttribute(attributeName="Title")
  public String getTitle() { return title; }    
  public void setTitle(String title) { this.title = title; }

}

Upvotes: 1

Related Questions