我有一个名为 opx_user_profiles 的 dynamodb 表。该实体如下所示,但属性 user_profile_id 在表中保存为 userProfileID,即使在属性上指定了 @DynamoDBAttribute(attributeName = USER_PROFILE_ID)。其他属性(例如 date_created)将按预期保存。
我已阅读文档,但仍然无法找到问题的根本原因。这是 dynamo DB 中的错误吗?
@DynamoDBTable(tableName = "opx_user_profiles")
public class UserProfileEntity implements Serializable
{
public static final String USER_PROFILE_ID="user_profile_id";
public static final String DATE_CREATED = "date_created";
public static final String EXPIRY_DATE = "expiry_date";
public static final String USERNAME ="username";
public static final String CONTACT_NAME ="contact_name";
private static final long serialVersionUID = 1L;
@DynamoDBAttribute(attributeName = USER_PROFILE_ID)
private Integer userProfileId;
@DynamoDBAttribute(attributeName = USERNAME)
private String userName;
@DynamoDBAttribute(attributeName = CONTACT_NAME)
private String contactName;
@DynamoDBAttribute(attributeName = DATE_CREATED)
private Date dateCreated;
@DynamoDBAttribute(attributeName = EXPIRY_DATE)
private long expiryDate;
public Integer getUserProfileID()
{
return userProfileId;
}
public void setUserProfileID(Integer userProfileId)
{
this.userProfileId = userProfileId;
}
public String getUserName()
{
return userName;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public String getContactName()
{
return contactName;
}
public void setContactName(String contactName)
{
this.contactName = contactName;
}
public Date getDateCreated()
{
return dateCreated;
}
public void setDateCreated(Date dateCreated)
{
this.dateCreated = dateCreated;
}
}
尽管AWS官方文档说我们可以应用注释@DynamoDBAttribute类字段,我无法让它像这样工作。然而,正如 AWS 中所见example,我可以毫无问题地将注释应用于 getter 方法。
请尝试以下操作:
@DynamoDBTable(tableName = "opx_user_profiles")
public class UserProfileEntity implements Serializable
{
public static final String USER_PROFILE_ID="user_profile_id";
...
private Integer userProfileId;
...
@DynamoDBAttribute(attributeName = USER_PROFILE_ID)
public Integer getUserProfileID()
{
return userProfileId;
}
public void setUserProfileID(Integer userProfileId)
{
this.userProfileId = userProfileId;
}
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)