Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDBMapper Table Generation Creating Only Index

I am trying to create tables in DynamoDB using the Java API.

Problem : It creates only the hash key index in the table and no other Attributes.

private void createTable(DynamoDBMapper mapper, AmazonDynamoDBClient amazonDynamoDBClient) {
    CreateTableRequest createTableRequest = mapper.generateCreateTableRequest(InsuranceData.class);
    createTableRequest.setProvisionedThroughput(new ProvisionedThroughput(25L, 25L));
    amazonDynamoDBClient.createTable(createTableRequest);
}


 private void run(){
    AmazonDynamoDBClient amazonDynamoDBClient = getDynamoDBLocalClient();
    DynamoDBMapper mapper = new DynamoDBMapper(amazonDynamoDBClient);
    InsuranceData insuranceData = new InsuranceData();
    createTable(mapper,amazonDynamoDBClient);
 }

POJO class

@DynamoDBTable(tableName = "InsuranceData")
public class InsuranceData {


private Integer siteId;
private String lob;
private InsuranceLobData multiItemLobData;
private InsuranceLobData standaloneLobData;

@DynamoDBHashKey(attributeName = "siteId")
public Integer getSiteId() {
    return siteId;
}

public void setSiteId(Integer siteId) {
    this.siteId = siteId;
}

@DynamoDBAttribute(attributeName = "F")
public String getLob() {
    return lob;
}

public void setLob(String lob) {
    this.lob = lob;
}

@DynamoDBTypeConverted(converter = InsuranceLobConverter.class)
public InsuranceLobData getMultiItemLobData() {
    return multiItemLobData;
}

public void setMultiItemLobData(InsuranceLobData multiItemLobData) {
    this.multiItemLobData = multiItemLobData;
}

@DynamoDBTypeConverted(converter = InsuranceLobConverter.class)
public InsuranceLobData getStandaloneLobData() {
    return standaloneLobData;
}

public void setStandaloneLobData(InsuranceLobData standaloneLobData) {
    this.standaloneLobData = standaloneLobData;
}
}

Converter

public class InsuranceLobConverter implements DynamoDBTypeConverter<String, InsuranceLobData> {
  private final static Gson gson = new Gson();


@Override
public String convert(InsuranceLobData object) {
    return gson.toJson(object);
}

@Override
public InsuranceLobData unconvert(String object) {
    return gson.fromJson(object, InsuranceLobData.class);
}

}

Can anybody see the problem here?

This Is Resolved

There was a problem the way I was storing my complex object InsuranceLobData.

@DynamoDBDocument
public class InsuranceLobData   {

private boolean isActive;
private Set<String> locale;
private AbacusData abacusData;
private boolean isActiveForMobile;
private boolean isActiveForDesktop;

@Override
public String toString() {
    return "InsuranceLobData{" +
            "isActive=" + isActive +
            ", locale=" + locale +
            ", abacusData=" + abacusData +
            ", isActiveForMobile=" + isActiveForMobile +
            ", isActiveForDesktop=" + isActiveForDesktop +
            '}';
}

public InsuranceLobData(){}


public InsuranceLobData(boolean isActive, Set<String> locale, AbacusData abacusData, boolean isActiveForMobile, boolean isActiveForDesktop) {
    this.isActive = isActive;
    this.locale = locale;
    this.abacusData = abacusData;
    this.isActiveForMobile = isActiveForMobile;
    this.isActiveForDesktop = isActiveForDesktop;
}

@DynamoDBAttribute(attributeName = "isActive")
public boolean isActive() {
    return isActive;
}

public void setActive(boolean active) {
    isActive = active;
}

@DynamoDBAttribute(attributeName = "locale")
public Set<String> getLocale() {
    return locale;
}

public void setLocale(Set<String> locale) {
    this.locale = locale;
}

@DynamoDBTypeConvertedJson
public AbacusData getAbacusData() {
    return abacusData;
}

public void setAbacusData(AbacusData abacusData) {
    this.abacusData = abacusData;
}

@DynamoDBAttribute(attributeName = "mobile")
public boolean isActiveForMobile() {
    return isActiveForMobile;
}
public void setActiveForMobile(boolean activeForMobile) {
    isActiveForMobile = activeForMobile;
}

@DynamoDBAttribute(attributeName = "desktop")
public boolean isActiveForDesktop() {
    return isActiveForDesktop;
}


public void setActiveForDesktop(boolean activeForDesktop) {
    isActiveForDesktop = activeForDesktop;
}

}

There was no need to add the DynamoDBDocument annotation. @DynamoDBDocument

like image 906
gursahib.singh.sahni Avatar asked Sep 03 '16 20:09

gursahib.singh.sahni


1 Answers

@DynamoDBTypeConverted(converter = InsuranceLobConverter.class)

was enough for DynamoDB to understand what sort of data i want to store in the database. Probably adding the annotation: @DynamoDBDocument to InsuranceLobData was confusing for it to understand the way it had to store the data.

So, removing the annotation @DynamoDBDocument worked for me.

Hope it helps others too.

like image 141
gursahib.singh.sahni Avatar answered Oct 14 '22 09:10

gursahib.singh.sahni