在TopLink JPA Annotation Reference的这些示例中:
例1-59 @OneToMany - 使用泛型的客户类
@Entity
public class Customer implements Serializable {
...
@OneToMany(cascade=ALL, mappedBy="customer")
public Set<Order> getOrders() {
return orders;
}
...
}
Run Code Online (Sandbox Code Playgroud)
例1-60 @ManyToOne - 带有泛型的订单类
@Entity
public class Order implements Serializable {
...
@ManyToOne
@JoinColumn(name="CUST_ID", nullable=false)
public Customer getCustomer() {
return customer;
}
...
}
Run Code Online (Sandbox Code Playgroud)
在我看来,该Customer实体是该协会的所有者.但是,在mappedBy同一文档中对属性的解释中,写成:
如果关系是双向的,则将关联的反向(非拥有)侧的mappedBy元素设置为拥有该关系的字段或属性的名称,如示例1-60所示.
但是,如果我没有错,看起来在示例中,mappedBy实际上是在关联的拥有方指定,而不是非拥有方.
所以我的问题基本上是:
在双向(一对多/多对一)关联中,哪个实体是所有者?我们如何指定一方作为所有者?我们如何指定多方作为所有者?
什么是"关联的反面"?我们怎样才能将一面指定为反面?我们如何将多边指定为反面?