Spring Roo 基数按属性映射

发布于 2024-12-23 17:06:04 字数 550 浏览 3 评论 0原文

我正在尝试使用 OneToMany 映射来映射 Address 实体和 Person 实体:“每个人只有一个地址,但一个地址可以有很多人”。

@RooJavaBean
@RooToString
@RooEntity(identifierColumn = "addressID")
public class Address {

    @OneToMany(cascade = CascadeType.ALL, **mappedBy = "address**")
    private Set<Person> persons = new HashSet<Person>();
}

我不知道用什么来映射地址实体(粗体),我对 JPA(Eclipse Link)和 Spring roo 的经验很少,但我认为 mappedBy 应该等于 addressID 并且对于双向ManyToOne 应该等于 personID 吗?

I am trying to map an Address entity and a Person entity using a OneToMany mapping: "Each person has only one address but an Address can have many people".

@RooJavaBean
@RooToString
@RooEntity(identifierColumn = "addressID")
public class Address {

    @OneToMany(cascade = CascadeType.ALL, **mappedBy = "address**")
    private Set<Person> persons = new HashSet<Person>();
}

I cannot figure out what to map the Address entity with (bold), i have very little experience with JPA(Eclipse Link) and Spring roo but i thought the mappedBy should equal addressID and for a bidirectional ManyToOne on my Person entity mappedBy should equal personID?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

无法回应 2024-12-30 17:06:04

正如任何 JPA 文档都会告诉您的那样(所有 JPA 实现都提供它们),mappedBy 是 Person 类中“Address”类型的字段的名称。如果 Person 中没有该类型的字段,则该关系不是双向的,因此您不使用“mappedBy”

As any JPA docs would tell you (all JPA implementations provide them), mappedBy is the name of the field of type "Address" in Person class. If you don't have a field of that type in Person, then the relation is not bidirectional and so you don't use "mappedBy"

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