How Do I: Define a Container-Managed Persistence (CMP) Field?

Container-managed persistence (CMP) fields are virtual fields in an entity bean. These fields are not defined in the entity bean itself but correspond to columns in the database table. The entity bean only implements the accessor (getter and setter) methods.

To Define a CMP Field

  1. Make sure that the entity bean is displayed in Design View.
  2. Right-click the right-hand area of the bean, and choose Add CMP Field. At the bottom of the bean, underneath CMP Fields, a new CMP field appears.
  3. Enter an appropriate name and Java type for the CMP field. Remember that only Java primitive types and Java serializable types are allowed.

The CMP field's accessor methods are now implemented. Right-click the field and choose Edit in Source View to examine the getter and setter method. Notice that by default the CMP field's accessor methods are defined in the entity bean's local interface, that is, are created with the @ejbgen:local-method tag.

To Change the CMP Field Properties

Although not recommended as a best practice, it is possible to define a CMP field in the remote interface only. To do so, go to source view and delete the ejbgen:local-method tag for its getter and setter method.

Related Topics

How Do I: Add a Business Method to an Entity Bean?

Developing Enterprise JavaBeans