@DynamoDBAttribute注释不起作用

Shubham Chopra:

我有一个名为opx_user_profiles的动态表。实体如下所示,但是,即使在属性上指定了@DynamoDBAttribute(attributeName = USER_PROFILE_ID),属性user_profile_id也已保存为表中的userProfileID。其他属性(如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 示例所示,我可以毫无疑问地将注释应用于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;
        }
        ...
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章