【发布时间】:2013-11-24 21:24:22
【问题描述】:
我不知道如何解决一个问题。我在春天有使用 MongoDb 的应用程序。我有两个对象任务和答案。每个答案都包含对任务的引用。问题是当我更新任务并且它没有更新答案中的任务时。可能是我设置错了,反正我也不知道是什么。
这是答案文件
@Document
public class Answer {
@Id
private String id;
private String text;
private Date created;
private Date finished;
@Reference
private Task task;
@Reference
private User user;
//constructor, getters and setters
任务文档
@Document
public class Task {
@Id
private String id;
private int percentageLimit = 75;
private int peopleLimit = 200;
private int priority = 0;
private int status = 0; //0=unfinished, 1=finished
private int visible = 1; //0=hidden, 1=visible
private Date created;
//constructor, getters and setters
在数据库中是这样的:
任务:
"_id" : ObjectId("...."),
"_class" : "com.example.model.Task",
"percentageLimit" : 75,
"peopleLimit" : 200,
"priority" : 10,
"status" : 0,
"visible" : 1,
"created" : ISODate("....")
答案:
"_id" : ObjectId("..."),
"_class" : "com.example.model.Answer"
....
....
"task" : {
"_id" : ObjectId{"...."}
"percentageLimit" : 75
...
"created" : ...
}
似乎没有参考,但正如你在上面看到的,我在任务上方的答案文档中有注释@Reference。
有人知道怎么解决吗?
非常感谢
迈克尔
【问题讨论】:
标签: java spring mongodb reference