java - Get reference to parent document from embedded document in Spring Data MongoDB -


I have access to the original object from an embedded object, but there can be no way to do it. Here I will show an example of this which means:

I have 2 Java Classics:

  @Document Public class parents {Private string name; Private listing & lt; Child & gt; children; @ Precision Concerter Generator (string name, list & lt; child & gt; children) {this.name = name; This.children = Children; } ... document public class child {personal string name; Private parents; @ Precision Constant Public Child (string name, parent parent) {this.name = name; This.parent = parents; } ...  

My document in MongoDB is such:

  {"name": "some names", "children": {"name" "Name1"}, {"name": "name2"}}  

Is it possible in the context of parents, for example, in the hair class Constructor? It seems that all parameters of the @stressistence constructor are annotated consultants in the children's class, which come from the children's array, which means that the parent named parameter comes in the form of zero: (

< P> I know that if I can make my own converter implementation, I can de-serialize parents and children and set myself in the context of parents, My actual document is quite large and writing de-serialization code will be quite boiler-plate code for me.

What you can do to manually set parent reference:

Child:

  @transent Personal parent parent, public watch settings (parent parent) { This.parent = parent;}  

@transient annotation tells the fields to ignore spring data. Gekt save time.

Then the parents:

  @ Precision Consestrctor Public Painter (string name, list, Little; Child & gt; Children) {this.name = name; Children = children; (Child.setParent (this);}} and some clever interfaces and the amount of duplicate code with subsidiary class or heritage will be less. (

>

Comments