gpt4 book ai didi

java - DynamoDBMapper 表生成仅创建索引

转载 作者:行者123 更新时间:2023-12-01 04:53:16 27 4
gpt4 key购买 nike

我正在尝试使用 Java API 在 DynamoDB 中创建表。

问题:它只在表中创建哈希键索引,没有其他属性。

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

}

有人能看到这里的问题吗?

已解决

我存储复杂对象的方式存在问题 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;
}

}

无需添加 DynamoDBDocument 注释。 @DynamoDBDocument

最佳答案

@DynamoDBTypeConverted(converter = InsuranceLobConverter.class)

足以让 DynamoDB 了解我想在数据库中存储什么样的数据。大概加了注解: @DynamoDBDocumentInsuranceLobData令人困惑的是它无法理解它必须存储数据的方式。

因此,删除注释 @DynamoDBDocument为我工作。

希望它也能帮助其他人。

关于java - DynamoDBMapper 表生成仅创建索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39310889/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com