Show TOC

Procedure documentationCreating Entities and Generating Database Tables Locate this document in the navigation structure

 

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

End of the caution.

Note Note

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

End of the note.

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 (New) pushbutton.

  2. Select   JPA   Entity  , then choose Next.

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

  4. Specify the properties of the entity.

    Note 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.

    End of the note.
  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 Note

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

For more information, see Generated Primary Keys.

End of the note.
3. Generate Tables from the Entities

Note Note

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

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

  2. In the context menu, choose   JPA Tools   Generate Tables from Entities  .

    Note Note

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

    End of the note.
  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   Project   Clean   in the main menu, then choose OK.