我有一个名为 SampleEntity 的类,即一个 POJO,它将帮助我创建我的 dynamoDB 表。哈希键和范围键已在 POJO 对象中明确定义,但我仍然得到一个异常,即未定义哈希键
@DynamoDBTable(tableName = "sampletable1")
public class SampleEntity {
public static final String HASH_KEY = "f1_hash";
public static final String RANGE_KEY = "f2_range";
@DynamoDBAttribute(attributeName = HASH_KEY)
@DynamoDBHashKey
private Integer feild1;
@DynamoDBAttribute(attributeName = RANGE_KEY)
@DynamoDBRangeKey
private String field2;
@DynamoDBAttribute(attributeName = "f3")
private String feild3;
@DynamoDBAttribute(attributeName = "f4")
private String feild4;
@DynamoDBAttribute(attributeName = "f5")
private String feild5;
public Integer getFeild1() {
return feild1;
}
public void setFeild1(Integer feild1) {
this.feild1 = feild1;
}
public String getField2() {
return field2;
}
public void setField2(String field2) {
this.field2 = field2;
}
public String getFeild3() {
return feild3;
}
public void setFeild3(String feild3) {
this.feild3 = feild3;
}
public String getFeild4() {
return feild4;
}
public void setFeild4(String feild4) {
this.feild4 = feild4;
}
public String getFeild5() {
return feild5;
}
public void setFeild5(String feild5) {
this.feild5 = feild5;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SampleEntity)) return false;
SampleEntity that = (SampleEntity) o;
if (!getFeild1().equals(that.getFeild1())) return false;
if (!getField2().equals(that.getField2())) return false;
if (!getFeild3().equals(that.getFeild3())) return false;
if (!getFeild4().equals(that.getFeild4())) return false;
return getFeild5().equals(that.getFeild5());
}
@Override
public int hashCode() {
int result = getFeild1().hashCode();
result = 31 * result + getField2().hashCode();
result = 31 * result + getFeild3().hashCode();
result = 31 * result + getFeild4().hashCode();
result = 31 * result + getFeild5().hashCode();
return result;
}
}
这是我的班级,我在这个班级上发出创建表请求,但我得到了不存在 HASH 键值的 DynamoDBMappingException。
server = ServerRunner.createServerFromCommandLineArgs(new String[]{"-inMemory", "-port", "8005"});
server.start();
dynamoDBClient = new AmazonDynamoDBClient(new BasicAWSCredentials("any", "thing")).withEndpoint("http://localhost:8005");
dbMapper = new DynamoDBMapper(dynamoDBClient);
CreateTableRequest createTableRequest = ddbMapper.generateCreateTableRequest(SampleEntity.class);
createTableRequest.setProvisionedThroughput(new ProvisionedThroughput(5L, 5L));
dynamoDBClient.createTable(createTableRequest);
SampleLoginEntity data= new SampleLoginEntity();
data.setLogin(123);
data.setField2("range");
data.setFeild3("abc");
dbMapper.save(data);