Chapter 7. Entity Relationships: When Beans Relate

image with no caption

Entity beans need relationships. An Order needs a Customer. A LineItem needs an Order. An Order needs LineItems. A Movie needs a Director. A Director needs Movies. A Movie needs Actors. An Actor needs talent... Entity beans can have container-managed relationships (CMR) and the Container takes care of virtually everything. Make a new Movie and give it a Director? That Director automatically has one more Movie in his Movie collection. Make a new LineItem that’s related to an Order? If you ask the Customer to show you his Orders, his Orders will show the new LineItem. Best of all, you can use EJB-QL to write portable (think: vendor/databse independent) queries.

Get Head First EJB 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.