Spring Roo 基数按属性映射
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如任何 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"