Best Practices

It is preferable to implement relationships between entity beans using container-managed persistence as opposed to bean-managed persistence for the following reasons:

  • The code is simpler to write. With BMP, you need to write code to manage relationships. With CMP, you need to declare how the relationships are managed in the deployment descriptor. The container generates all the relationship code.

  • The container automatically handles referential integrity. For example, in a one-to-one relationship, if you change one side of the relationship, the container automatically drops the old relationship and replaces it with the newly formed one-to-one relationship.

  • Containers typically provide performance optimizations, such as optimizing ...

Get Sams Teach Yourself EJB in 21 Days 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.