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:
- 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 Runtime 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 > Entity
Beans from Database.
- Select the database source:
- JDBC Connection. The combo box lists all your registered database
connections. You can add a database connection by choosing Add Connection
from the combo box.
- Database Schema. The combo box lists 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 combo box, select the source root to which you want to add
the enterprise beans .
- In the Package combo box, 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 in 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 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. You can view and edit relationships by expanding the
project's Configuration Files node, double-clicking ejb-jar.xml,
and clicking CMP Relationships in the top of the visual editor.
If your project's target server is the Sun Java System Application Server, the IDE also
does the following:
- Creates a sun-cmp-mappings.xml file in your configuration files
folder 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,
selecting the bean in the visual editor, and selecting the CMP Mapping tab.
- 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 under the Server Resources node.
- If you are deploying to the JBoss or WebLogic application 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 Entity Beans
- Creating
a Database Schema
Legal Notices