Note that there are some explanatory texts on larger screens.

plurals
  1. POIn a bidirectional JPA OneToMany/ManyToOne association, what is meant by "the inverse side of the association"?
    text
    copied!<p>In these examples on <a href="http://www.oracle.com/technetwork/middleware/ias/toplink-jpa-annotations-096251.html#OneToMany" rel="noreferrer">TopLink JPA Annotation Reference</a>:</p> <p><strong>Example 1-59 @OneToMany - Customer Class With Generics</strong></p> <pre><code>@Entity public class Customer implements Serializable { ... @OneToMany(cascade=ALL, mappedBy="customer") public Set&lt;Order&gt; getOrders() { return orders; } ... } </code></pre> <p><strong>Example 1-60 @ManyToOne - Order Class With Generics</strong></p> <pre><code>@Entity public class Order implements Serializable { ... @ManyToOne @JoinColumn(name="CUST_ID", nullable=false) public Customer getCustomer() { return customer; } ... } </code></pre> <p>It seems to me that the <code>Customer</code> entity is the owner of the association. However, in the explanation for the <code>mappedBy</code> attribute in the same document, it is written that:</p> <blockquote> <p>if the relationship is bidirectional, then set the mappedBy element on the inverse (non-owning) side of the association to the name of the field or property that owns the relationship as Example 1-60 shows.</p> </blockquote> <p>However, if I am not wrong, it looks like in the example, the <code>mappedBy</code> is actually specified on the owning side of the association, rather than the non-owning side.</p> <p>So my question is basically:</p> <ol> <li><p>In a bidirectional (one-to-many/many-to-one) association, which of the entities is the owner? How can we designate the One side as the owner? How can we designate the Many side as the owner?</p></li> <li><p>What is meant by "the inverse side of the association"? How can we designate the One side as the inverse? How can we designate the Many side as the inverse?</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload