Defining a CMP Field
See Also
An EJB 2.1 entity bean is the tool that a J2EE 1.4 enterprise application
uses to represent data in a database. If it uses container-managed
persistence (CMP), the bean must have a set of CMP fields that the container
uses to map to fields in the database.
To define a CMP field for an existing entity bean:
- Open the bean class in the Source Editor.
- Right-click anywhere inside the body of the class and choose EJB Methods
> Add
CMP Field. This command is only enabled when you click within the body of
the class (after the class declaration).
You can also right-click enterprise bean's node in the Projects window and
choose Add > Add CMP Field.
- Enter the name and type of the CMP field and click OK.
When you add a new CMP field to an entity bean, the IDE does the following:
- Adds the get and set methods for the field to the bean class.
- Registers the CMP field in the deployment descriptor.
To view or edit an existing CMP field:
- In the Projects window, expand the Configuration Files node for your EJB
module project.
- Double-click ejb-jar.xml. The graphical editor opens in the Details
view.
- Expand the header for the entity bean node and the CMP Fields header. The
table lists all of the existing CMP fields.
- Click Add or Edit to make changes to the list of CMP fields.
Notes:
- If you use the Entity Beans from Database
wizard to create the bean, the IDE can automatically create the CMP fields
for all the fields in a database.
- The new CMP field might require some server specific configuration. For
example, it might need to be mapped to a database column for the Sun Java
System Application Server in sun-ejb-jar.xml or sun-cmp-mapping.xml.
- See Also
- About Entity Beans
- Creating an Enterprise Bean
- Generating CMP Entity Beans from a Database
- Defining a Select Method
- Defining a Finder Method
- Connecting to a Database
- Obtaining a Database Schema
Legal Notices