0

I don't know how to solve one problem. I have application in spring using MongoDb. I have two objects Task and Answer. Every Answer contains Referenence to Task. Problem is when I am updating Task and It doesn't update Task in Answer. Maybe I've set up someting wrong, anyway I don't know what.

Here is Answer document

@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

Task document

@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

In database it looks like this:

Task:

"_id" : ObjectId("...."),
"_class" : "com.example.model.Task",
"percentageLimit" : 75,
"peopleLimit" : 200,
"priority" : 10,
"status" : 0,
"visible" : 1,
"created" : ISODate("....")

Answer:

"_id" : ObjectId("..."),
"_class" : "com.example.model.Answer"
....
....
"task" : {
    "_id" : ObjectId{"...."}
    "percentageLimit" : 75
    ...
    "created" : ...
}

It seems like there is no reference, but as you can see upper I have annotation @Reference in Answer document right above Task.

Does somebody know how to solve this?

Thanks a lot

Michal

Ori Dar
  • 18,687
  • 5
  • 58
  • 72
Michal Majernik
  • 395
  • 1
  • 3
  • 11

1 Answers1

1

You should change @Reference annotation to @DBRef

Ori Dar
  • 18,687
  • 5
  • 58
  • 72