Show TOC

Creating Entities and Generating Database TablesLocate this document in the navigation structure

Use

This procedure describes how to create entities manually and use the automatic generation of database tables function (also called “forward mapping” ) which is provided by SAP NetWeaver Developer Studio.

The generation of database tables from entities depends on how the object-relational mapping of the entities is organized. The object-relational mapping process includes mapping the entity to a table, specifying an entity field as a primary key, associating entity fields to table columns, defining entities' relationships, inheritance, and so on.

Once you have mapped the entity to the relational database, you can use either Java Dictionary or a custom database schema for the generation of database tables from entities.

Caution

If you are using Java Dictionary for the forward mapping, you have to consider the following requirements when specifying the object-relational mapping:

  • The table names must be in upper case.

  • A prefix of the table name is required, for example, TMP_EMPLOYEE .

  • The table names' length must not exceed 18 characters.

Note

The forward mapping does not create foreign key constraints on the database.

Prerequisites

You have created a project (for example, JPA, EJB, or Dynamic Web) to store the entities, and associated it to a Java Dictionary connection or to a database connection.

Procedure

1. Create the Entities

  1. Choose the New pushbutton.

  2. Select Start of the navigation path JPA Next navigation step Entity End of the navigation path, then choose Next .

  3. Specify the required details of the entity class, then choose Next .

  4. Specify the properties of the entity.

    Note
    • The data type of the entity primary key must be one of the following:

      • A primitive Java type

      • A primitive wrapper type

      • java.lang.String

      • java.util.Date

      • java.sql.Date

    • To create a composite primary key, add the primary key fields and select their Key checkboxes. The composite primary key class is generated together with the entity.

  5. Choose Finish .

2. Specify the Object-Relational Mapping of the Entities.

For more information about the object-relational mapping tools, refer to the “Dali Java Persistence Tools User Guide” , provided by the Developer Studio help content.

Note

Instead of specifying the entities' primary keys explicitly, you can also have them generated automatically.

For more information, see Generated Primary Keys .

3. Generate Tables from the Entities

Note

To perform forward mapping, you must have specified the object-relational mapping of your entities.

  1. In the Project Explorer , select the project that contains your entities.

  2. In the context menu, choose Start of the navigation path JPA Tools Next navigation step Generate Tables from Entities End of the navigation path.

    Note

    If your project is associated with a Java Dictionary connection profile, the table generation is completed with this step.

  3. Fill out the required data:

    • Project - the project that contains the entities used for table generation

    • File - the name of the DDL script file to be created

    • Generate - additional properties to be used for the table generation

  4. Choose Next , then choose Finish .

    The Developer Studio generates and opens the DDL script file in the standard SQL editor.

  5. If necessary, specify the details of the database connection you are using:

    • Type of the connection profile

    • Name of the connection profile

    • Database - the name of the database

  6. In the context menu of the DDL script, choose Execute All .

    The actual forward mapping is completed.

    To see the generated tables under the relevant database node in the Data Source Explorer , you have to refresh the database and perform a clean build of the project that contains the entities.

  7. To refresh the database in the Data Source Explorer , choose Refresh in the context menu.

  8. To perform a clean build of the project, choose Start of the navigation path Project Next navigation step Clean End of the navigation path in the main menu, then choose OK .