In a bidirectional JPA OneToMany/ManyToOne association, what is meant by "the inverse side of the as

Posted by Bytecode Ninja on Stack Overflow See other posts from Stack Overflow or by Bytecode Ninja
Published on 2010-04-06T11:46:01Z Indexed on 2010/04/06 12:03 UTC
Read the original article Hit count: 314

Filed under:
|
|

In these examples on TopLink JPA Annotation Reference:

Example 1-59 @OneToMany - Customer Class With Generics

@Entity
public class Customer implements Serializable {
    ...
    @OneToMany(cascade=ALL, mappedBy="customer")
    public Set<Order> getOrders() { 
        return orders; 
    }
    ...
}

Example 1-60 @ManyToOne - Order Class With Generics

@Entity
public class Order implements Serializable {
    ...
    @ManyToOne
    @JoinColumn(name="CUST_ID", nullable=false)
    public Customer getCustomer() { 
        return customer; 
    }
    ...
}

It seams to me that the Customer entity is the owner of the association. However, in the explanation for the mappedBy attribute in the same document, it is written that:

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.

However, if I am not wrong, looks like in the example the mappedBy is actually specified on the owning side of the association, rather than the non-owning side.

So my question is basically:

  1. 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?

  2. 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?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about jpa

Related posts about hibernate