Diego Perez Diego Perez - 13 days ago 5
Android Question

Android and DynamoDB. Not being able to add an attribute to table

I created a table in AWS DynamoDB which I'll be using for a basic questions and answers forum I'm developing and after table creation and some successful tests where I was able to insert data I decided to add an attribute for storing date of question, which I called time_stamp but for an unknown reason for me I'm not being able to refresh table structure, I mean, data is still saved with no errors but with no time_stamp field.

I tried deleting the table and recreating several times and modifying time_stamp data type with no success so I'm lost and I hope anyone can help me. I thought the only neccesary thing to alter table structure in DynamoDB is just modifing the mapping class in Java but cannot make it to work.

My mapping class is the next:

import com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.*;

@DynamoDBTable(tableName = "community_questions")
public class CommunityQuestion {

private long question_id;
private String time_stamp;
private String user_id;
private String subject;
private String question;

@DynamoDBHashKey(attributeName = "question_id")
public long getQuestionId() { return question_id; }

public void setQuestionId(long questionId) { this.question_id = questionId; }

@DynamoDBAttribute (attributeName = "time_stamp")
public String geTimeStamp() {
return time_stamp;
}

public void setTimeStamp(String timeStamp) {
this.time_stamp = timeStamp;
}

@DynamoDBAttribute (attributeName = "user_id")
public String getUserId() {
return user_id;
}

public void setUserId(String userId) {
this.user_id = userId;
}

@DynamoDBAttribute(attributeName = "subject")
public String getSubject() {
return subject;
}

public void setSubject(String subject) {
this.subject = subject;
}

@DynamoDBAttribute(attributeName = "question")
public String getQuestion() {
return question;
}

public void setQuestion(String question) {
this.question = question;
}
}


All data is being saved with no errors but time_stamp won't!!

I'm using
mapper.save
for saving operations.

Maybe anything I should refresh in AWS console?? Can't find anything.

Please help, and many thanks in advance.

Answer

There is a typo in your code. Rename geTimeStamp to getTimeStamp

DynamoDbMapper considers only methods with exactly "get" or "is" prefixes, and then checks for annotations on those in a second step. Its not picking up your added property because of that.

/**
 * Returns whether the method given is a getter method we should serialize /
 * deserialize to the service. The method must begin with "get" or "is",
 * have no arguments, belong to a class that declares its table, and not be
 * marked ignored.
 */
 private static boolean isRelevantGetter(Method m) {

(soure)