Generating CMP Entity Beans from a Database
See Also
In addition to writing CMP entity
beans from scratch, you can also generate a set of CMP entity beans for
an existing database. You can generate CMP entity beans from an existing database
connection or from a database schema.
- Make sure that you have access to the database source from which you want
to generate the entity beans:
- If you want to generate entity beans from an existing database connection,
make sure the database is running and you have
registered a connection
to it in the Services window.
- If you want to use a database schema, make sure the database schema
file exists in your project's conf folder.
- Right-click the EJB module project node in the Projects window and choose
New > CMP Entity Beans from Database.
- Select the database source:
- JDBC Connection. The drop-down list displays all your registered database
connections. You can add a database connection by choosing Add Connection
from the drop-down list.
- Database Schema. The drop-down list displays all of the database schema
files in your project's conf folder. If your project does not
contain any database schema files, this option is disabled.
- In the Location drop-down list, select the source root to which you want to add the enterprise beans .
- In the Package drop-down list, select an existing package or type a new package name.
- Specify whether to generate finder methods for all CMP fields.
- Specify whether to add the CMP Fields and CMR fields to the local interfaces.
- Click Next.
- Select any table from the list on the left and click Add. Then click Finish.
When you generate entity beans from a database, the IDE does the following:
- If creating the entity beans from a database connection, grabs the database
structure and stores it in a database schema file in your project's conf
folder.
- Creates an entity bean for each of the selected tables and any tables the selected
tables reference. A node for each entity bean is displayed in the project's
Enterprise Beans node. By default, the generated entity beans only have local
interfaces. Each entity bean contains a CMP field for each column in the table
and a CMR field for any column that references another table.
- Configures any container-managed relationships in the EJB module's ejb-jar.xml
deployment descriptor.
If your project's target server is the Sun Java System Application Server/GlassFish, the IDE also
does the following:
- Creates a sun-cmp-mappings.xml file under the Configuration Files
node that contains CMP mapping information for the entity beans. The IDE
maps all CMP fields to the correct columns in the database. You can view and
edit CMP mappings by double-clicking sun-ejb-jar.xml or sun-cmp-mappings.xml,
and then clicking the XML tab to edit the file in the XML editor.
- Prepares a connection object and JDBC resources for the project which are
configured on the server when you run or deploy the project. You can view
and edit these resources in the sun-resources.xml file under the Server Resources node in the Projects window.
- If you are deploying to the JBoss or Oracle WebLogic Servers, you have
to write your server-specific deployment descriptors and configure the required
server resources yourself.
- See Also
- Creating an EJB Module Project
- Creating an Enterprise Application Project
- About Creating Web Applications
- Creating an Enterprise Bean
- About EJB 2.1 Entity Beans
- Creating a Database Schema
Legal Notices