Chapter 7. Entity Relationships
Chapter 6 covered basic persistence mappings, including various ways to define primary keys as well as simple and complex property-type mappings. This chapter develops our Titan Cruises application a bit further by discussing the seven relationships that entity beans can have with each other.
In order to model real-world business concepts, entity beans must
be capable of forming complex relationships. If we turned our embedded
Address
object in Chapter 6 into a first-class entity
bean, we would have had a one-to-one relationship between our Customer
entity and an Address entity. The Address could be queried and cached
like any other entity, yet a close relationship would be forged with the
Customer entity. Entity beans can also have one-to-many, many-to-one,
and many-to-many relationships. For example, the Customer entity may
have many phone numbers, but each phone number belongs to only one
customer (a one-to-many relationship). A customer may have been on many
cruises, and each cruise has many customers (a many-to-many
relationship).
The Seven Relationship Types
Seven types of relationships can exist between entity beans. There are four types of cardinality: one-to-one, one-to-many, many-to-one, and many-to-many. In addition, each relationship can be either unidirectional or bidirectional. These options seem to yield eight possibilities, but if you think about it, you’ll realize that one-to-many and many-to-one bidirectional relationships ...
Get Enterprise JavaBeans 3.0, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.