英文:
Use of DynamoDB annotations in nested objects
问题
我正试图在嵌套对象中使用DynamoDB注解,如下所示:
@DynamoDBTable(tableName=xyz)
class entity1{
@DynamoDBAttribute
@DynamoDBTypeConvertedJson
private List<UserAction> userActions;
}
class UserAction{
@DynamoDBAutoGeneratedKey
private String actionId;
@DynamoDBAttribute
@DynamoDBAutoGeneratedTimestamp(strategy = DynamoDBAutoGenerateStrategy.CREATE)
private Long createdTime;
}
我没有看到上述属性在UserAction类中被自动生成。我想知道这些注解用法是否支持嵌套对象。请提供建议。
英文:
I am trying to use DynamoDB annotations in nested objects as below:
@DynamoDBTable(tableName=xyz)
class entity1{
@DynamoDBAttribute
@DynamoDBTypeConvertedJson
private List<UserAction> userActions;
}
class UserAction{
@DynamoDBAutoGeneratedKey
private String actionId;
@DynamoDBAttribute
@DynamoDBAutoGeneratedTimestamp(strategy = DynamoDBAutoGenerateStrategy.CREATE)
private Long createdTime;
}
I dont see the above attributes are auto generated in UserAction class. I would like to know if these annotation usages are supported in nested objects or not. Please suggest.
答案1
得分: 2
在 UserAction 类上添加 @DynamoDbDocument 注释。此注释将确保在将 UserAction 类的实例持久化到表中之前,它会被正确地序列化为 Dynamo DB 子文档。
@DynamoDbDocument
class UserAction {
//...............
//...............
}
英文:
Add @DynamoDbDocument annotation on UserAction class. This annotation will ensure the instance of UserAction class is correctly serialized to a Dynamo DB sub-document before persisting in table.
@DynamoDbDocument
class UserAction{
//...............
//...............
}
答案2
得分: 1
以下是标有注释的方法,用于查找 @DynamoDBDocument
的 v2 版本等效方式。有关更多信息,请查看此链接。
@DynamoDbBean
class entity1 {
private List<UserAction> userActions;
}
@DynamoDbBean
class UserAction {
private String actionId;
private Long createdTime;
}
英文:
If anyone is looking for a v2 equivalent of @DynamoDBDocument
, the following is the annotated way of doing it. For more information check this out.
@DynamoDbBean
class entity1 {
private List<UserAction> userActions;
}
@DynamoDbBean
class UserAction {
private String actionId;
private Long createdTime;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论