Entities do not exist in isolation but are usually associated with other entities. This chapter examined how we map these associations onto a relational database. We first looked at an example with unidirectional one-to-one, one-to-many, and many-to-many associations. We described the @OneToOne, @OneToMany
and @ManyToMany
annotations for mapping associations to a relational database. Initially we relied on default object/relational mapping values.
We then described a bidirectional example and showed how we could override default object/relational mapping values.
We described eager and lazy loading mechanisms. We gave examples of the @Embedded, @Embeddable, @Enumerated
and @MapKey
annotations. We saw how to handle composite primary keys.
Finally we looked at a number of object/relational inheritance mapping strategies.