自引用表的 Yaml
我的模型定义如下:
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;
}
我无法为 yaml 中的前两项指定父项来竞争我的数据
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
链接到链接父子关系的所有权位于子对象上。所有权由mappedBy-parameter中定义,
因此您应该首先在YAML中声明您的父对象,并省略父对象中的“children”字段。然后,您可以在父对象声明之后添加子对象声明,并向
子对象添加字段。它应该是这样的:
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: