Entities do not exist in isolation and are usually associated with other entities. In this chapter we examine how to map these associations onto a relational database. We will cover the following topics:
One-to-one, one-to-many, and many-to-many associations.
Default object/relational mapping values.
Overriding the default object/relational mapping values.
The
@Embedded, @Embeddable, @Enumerated
, and@MapKey
annotations.Composite primary keys
Entity inheritance mapping strategies
In the previous chapter we saw how to persist individual entities to a relational database. In this chapter, we take a further look at object-relational mapping with EJB 3. In any real world application, entities do not exist in isolation but have relationships with other entities. In this chapter we shall see how these relationships are mapped onto a relational database.
Object-relational mapping is specified using annotations, but XML mapping files can...