英文:
Can't use @Embedded for a list of Objects Morphia
问题
以下是翻译的内容:
这是我拥有的主要文档类型:
@Entity("users")
public class UserModel {
@Id
private ObjectId id;
private String userID;
private String prefix;
@Embedded
private List<TodoList> todoLists;
@Embedded
private List<Reminder> reminders;
// 获取器,设置器,构造函数
}
这是代替的TodoList类:
@Embedded
public class TodoList {
@Id
private ObjectId id;
private String name;
private List<String> todos;
private List<String> completed;
}
对于List
UserModel.java:18: 错误: 注解类型不适用于此类型的声明
@Embedded
我真的不明白我做错了什么…
(我正在使用Morphia 2.0.1,甚至将一个简单的TodoList类放在这些类的列表中也会引发该错误)
英文:
This is the main Document type I have
@Entity("users")
public class UserModel {
@Id
private ObjectId id;
private String userID;
private String prefix;
@Embedded
private List<TodoList> todoLists;
@Embedded
private List<Reminder> reminders;
// Getters, setters, constructor
This is the TodoList class instead:
@Embedded
public class TodoList {
@Id
private ObjectId id;
private String name;
private List<String> todos;
private List<String> completed;
I get this error for the @Embedded annotation of the List<TodoList>:
UserModel.java:18: error: annotation type not applicable to this kind of declaration
@Embedded
I can't really understand what I'm doing wrong...
(I'm using Morphia 2.0.1 and even putting a simple TodoList class instead of a list of those classes throws that error)
答案1
得分: 2
刚刚发现 @Embedded 不能用于字段,只能用于类上。所以我只需将它从 UserModel 中移除,保留在 TodoList 类中。
英文:
Just found out that @Embedded is not usable on fields, but just on classes. So I just had to simply remove it from the UserModel and keep it in the TodoList class.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论