1

I have two classes:

class Person {
  @DBRef
  @JsonManagedReference
  private List<Task> tasks;
}

class Task {
  @DBRef
  @JsonBackReference
  private Person person;
}

When I query to find all Persons the list of Tasks is populated with the associated Tasks. That's what I want.

When I query to find all Tasks, I expected to receive an Task object with the associate Person on it, but I'm receiving without the Person field as null. I want to receive the associated Person as well.

Lucas Beier
  • 621
  • 1
  • 7
  • 19
  • that is supposed to work as described. Can you share a bit more details on how you actually persist your data (code snipped, gist, whatever...) and which version of spring-data-mongodb you are using? – Christoph Strobl Nov 16 '15 at 10:40
  • To save both Person and Task I'm using the ```mongoOperations.insert``` and passing the object as param. I'm using the version ```1.6.1.RELEASE``` of spring-data-mongodb. – Lucas Beier Nov 16 '15 at 12:59
  • I found this question and it's basically what I want to do. https://stackoverflow.com/questions/10065002/jackson-serialization-of-entities-with-birectional-relationships-avoiding-cyc The answer talks about using ```@JsonIdentityInfo```. I tried but with no luck. Didn't figure out which Generator I should use. – Lucas Beier Nov 16 '15 at 13:18

0 Answers0