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.

To generate database tables at runtime:

  1. Make sure that your entity beans are set to use container-managed persistence and have their CMP fields and container-managed relationships correctly configured.
  2. In the Projects window, expand Configuration Files and double-click sun-ejb-jar.xml to open the Sun Configuration editor.
  3. 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.
  4. 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.

  5. 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.
  6. 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