concept related entity in category ejb

appears as: related entities
EJB 3 in Action, Second Edition

This is an excerpt from Manning's book EJB 3 in Action, Second Edition.

While not as common as one-to-many, many-to-many relationships occur quite frequently in Enterprise applications. In this type of relationship, both sides might have multiple references to related entities. In the ActionBazaar example, the relationship between Category and Item is many-to-many, as shown in figure 9.8.

Loading related entities

One of the most intricate uses of fetch modes is to control the retrieval of related entities. Not surprisingly, the EntityManager's find method must retrieve all entities related to the one returned by the method. Let’s take the ActionBazaar Item entity, an exceptionally good case because it has a many-to-one, a one-to-many, and two many-to-many relationships. The only relationship type not represented is one-to-one. The Item entity has a many-to-one relationship with the Seller entity (a seller can sell more than one item, but an item can be sold by only one seller), a one-to-many relationship with the Bid entity (more than one bid can be put on an item), and a many-to-many relationship with the Category entity (an item can belong to more than one category and a category contains multiple items). These relationships are depicted in figure 10.7.