Design Notes for CMP Entity Beans

There is a small, but significant, difference between how you design using BMP and CMP Entity beans. As the container manages persistence of CMP and CMR fields you cannot perform an application level validation on these fields. Put simply:

  • With BMP Entity beans, you write the getter and setter methods for all bean properties and can validate or modify the property values with the code.

  • With CMP Entity beans, the J2EE container generates the code for the getter and setter methods for the bean properties and you cannot define any additional validation or modification.

This leads to one simple rule:

  • Avoid exposing CMP and CMR fields to Entity Bean clients.

As a simple example consider the email CMP field of the ...

Get Sams Teach Yourself J2EE™ in 21 Days, Second 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.