I have a model defined as follows:
public class Link extends Model {
@Required
public String tag;
@Required
public String type;
@Required
public int weight;
@ManyToOne(cascade = CascadeType.ALL)
public Link parent;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
public List<Link> children;
@ManyToMany(cascade = CascadeType.PERSIST)
public List<Tag> tags;
}
I am unable to specify parent for the first two items in the yaml to compete my data
Link(m):
tag: m
type: home
weight: 1
tags:
- tagH
- tagM
Link(hh):
tag: hh
type: home
weight: 2
tags:
- tagH
- tagHH
artoo.Link(focus):
tag: focus
type: footer
weight: 1
tags:
- tagTechnology
- tagLegal
children:
- m
- hh
The ownership of your Link-to-Link parent-child relationship is on the child object. The ownership is defined by mappedBy-parameter in
Therefore you should first declare your parent objcect in YAML, and omit the “children” field from the parent. Then you can add the children object declarations after the parent object declaration and add fields
to the children objects. It should be something like this: