About EJB 2.1 CMP Mappings

See Also

The term container-managed persistence (CMP) means that the EJB container handles all database access required by the entity bean. When coding to the J2EE 1.4 specification, you create CMP entity beans and then describe how the entity beans are mapped to tables in your database in a .

If you are deploying to the Sun Java System Application Server/GlassFish, the CMP mappings for your EJB module are specified in the sun-cmp-mappings.xml descriptor file in the module's src/conf directory. If you generate CMP entity beans from a datasource, the IDE generates sun-cmp-mappings.xml for you when you create the CMP entity beans. To edit CMP mappings, you need to open sun-cmp-mappings.xml in the XML editor.

The sun-cmp-mapping.xml descriptor file describes how the entity beans, CMP fields and CMR relationships are mapped to the database. The bean's code contains no database access (SQL) calls. As a result, the bean's code is not tied to a specific persistent storage mechanism (database). Because of this flexibility, even if you redeploy the same entity bean to different J2EE servers that use different databases, you do not need to modify or recompile the bean's code. This makes your entity beans more portable.

In order to generate the data access calls, you have to provide a schema that defines the bean's persistent fields and relationships. Your CMP entity beans mirror the structure of your database. The beans' CMP fields correspond to the columns in the database tables and the relationship fields correspond to foreign keys in the database.

Configuring CMP Mappings in the IDE

If you are deploying to the Sun Java System Application Server, the IDE can assist you in generating CMP mappings. If you are deploying to a different application server, you have to configure CMP mappings yourself by editing the server-specific deployment descriptors.

There are three strategies for working with CMP mappings in the IDE:

For a detailed description of CMP entity bean specifications, see the Enterprise JavaBeans Specification, v2.1.

See Also
Defining a CMP Field
Generating CMP Entity Beans from a Database
Managing Container-Managed Relationships
Obtaining a Database Schema
Configuring CMP Mappings
Mapping Relationship Fields
Generating Database Tables at Deployment

Legal Notices