Generating Database Tables at Deployment
See Also
When developing CMP entity beans, if your only requirement is that the beans
are persisted to a database and you are not particular about the structure of
the database, you can configure the application such that the database and mappings
will be generated by the application server. In this case, you can create your
CMP entity beans, the bean fields, and the relationships in the IDE. You then
configure the application to generate the database tables and mappings when
you deploy the application.
- Unless you create
entity beans from a database connection, the IDE assumes you want to generate
the sun-cmp-mappings.xml file automatically. If you create CMP entity
beans using the New
Entity Bean template and manually set up your mappings, either in the
Sun Configuration Editor or by hand in a sun-cmp-mappings.xml file,
the IDE ignores your settings and configures the mappings during deployment.
To use your own sun-cmp-mappings.xml file, do one of the following:
- Generate a CMP entity bean from any database. You can then delete the
bean. The IDE automatically switches your project to pick up the existing
sun-cmp-mappings.xml file.
- Open the project's nbproject/project.properties file and remove
sun-cmp-mappings.xml from the project's meta.inf.excludes
property.
To generate database tables at runtime:
- Make sure that your entity beans are set to use container-managed persistence
and have their CMP fields and container-managed relationships correctly configured.
- In the Projects window, expand Configuration Files and double-click sun-ejb-jar.xml
to open the Sun Configuration editor.
- With the top-level Sun Configuration node selected in the left frame, specify
the JNDI name for your database resource in the Jndi Name field. Make sure
that the name matches a database resource configured on your application server.
- Set Create Table at Deploy to True.
To prevent an error when redeploying the application, set Drop Table At
Undeployment to True. Alternatively, you can delete the tables manually
in the Runtime window of the IDE.
- Make sure the database server in which you are generating the tables is
running. If you are using the bundled PointBase server, choose Tools >
PointBase Database > Start Local PointBase Database.
- Deploy your application by right-clicking the project node and choosing
Run Project.
The application server creates a table for each CMP bean. In each table, a
column is created for each CMP field and the relationships between the tables
are generated based upon the relationships between your CMP beans. You can see
the created tables under the Tables node for your database connection in the
Runtime window.
- See Also
- About EJB 2.1 CMP Mappings
- Defining a CMP Field
- Mapping Relationship Fields
- Generating CMP Entity Beans from a Database
- Configuring CMP Mappings
- Specifying Primary and Secondary Tables
Legal Notices