自引用表的 Yaml

发布于 2025-01-06 19:34:16 字数 847 浏览 4 评论 0原文

我的模型定义如下:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黎夕旧梦 2025-01-13 19:34:16

链接到链接父子关系的所有权位于子对象上。所有权由mappedBy-parameter中定义,

@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)

因此您应该首先在YAML中声明您的父对象,并省略父对象中的“children”字段。然后,您可以在父对象声明之后添加子对象声明,并向

parent: focus

子对象添加字段。它应该是这样的:

Link(focus):
    ...

Link(m):
    parent: focus

Link(hh):
    parent: focus

The ownership of your Link-to-Link parent-child relationship is on the child object. The ownership is defined by mappedBy-parameter in

@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)

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

parent: focus

to the children objects. It should be something like this:

Link(focus):
    ...

Link(m):
    parent: focus

Link(hh):
    parent: focus
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文