O'Reilly logo

Enterprise JavaBeans, Fourth Edition by Richard Monson-Haefel, Bill Burke, Sacha Labourey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7. CMP: Entity Relationships

Chapter 6 covered basic container-managed persistence (CMP), including container-managed persistence fields and an introduction to a basic container-managed relationship field. This chapter develops the Customer EJB and discusses 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. Chapter 6 demonstrated a one-to-one relationship between the Customer and Address EJBs. This relationship was unidirectional: the Customer had a reference to the Address, but the Address did not have a reference back to the Customer. This is a perfectly legitimate relationship, but other relationships are possible. For example, each Address could also reference its Customer, a bidirectional, one-to-one relationship in which both participants maintain references to each other. Entity beans can also have one-to-many, many-to-one, and many-to-many relationships. For example, the Customer EJB 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 EJBs. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required