Notice that the field is decorated with a @ManyToOne annotation. This annotation
marks the many side of the one-to-many relationship between Customer and
Address . Notice that the field is also decorated with the @JoinColumn annotation.
The name attribute of this annotation indicates the column in the database our
entity maps to that defines the foreign key constraint between the ADDRESS and
CUSTOMER tables (in our case, the CUSTOMER_ID column on the ADDRESS table). The
referencedColumnName attribute of @JoinColumn is used to indicate the primary
key column of the table on one side of the relationship (in our case, the CUSTOMER_ID
column in the CUSTOMER table).
In addition to one-to-many and many-to-one relationships, JPA provides annotations
to denote many-to-many and one-to-one relationships. In our schema, we have a
many-to-many relationship between the CUSTOMER_ORDER and ITEM tables; since
an order can have many items, and an item can belong to many orders.
The table to hold orders was named CUSTOMER_ORDER since the word
"order" is a reserved word in SQL.
Let's take a look at the CustomerOrder JPA entity to see how the many-to-many
relationship is defined:
@Table(name = "CUSTOMER_ORDER")