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

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 the Java Dictionary or a physical database for the generation of database tables from entities.

Caution Caution

If you are using the 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 tool does not create foreign key constraints on the database.

End of the note.

Prerequisites

Procedure

Creating Entities
  1. Choose the New (New) pushbutton.

  2. Select   JPA   Entity  , then choose Next.

  3. Specify the details of the entity class:

    1. Select the Project to be used for the entity.

    2. (Optional) Select the Source folder of the project to store the entity.

    3. Specify a Java package to contain the entity.

    4. Enter a Class name of the entity.

    5. If necessary, specify a Superclass.

    6. If necessary, specify the inheritance details:

      • Define the new class as an Entity or a Mapped Superclass.

      • To configure an inheritance strategy, select the Inheritance checkbox, and select a strategy from the dropdown list.

      More information: Inheritance

    7. (Optional) Select the Add to entity mappings in XML checkbox.

  4. Choose Next.

  5. Specify the details of the entity:

    1. Enter an Entity Name.

    2. To specify a custom table name for the entity, deselect the Use default checkbox and fill out the Table Name field.

    3. To add a new field to the entity, choose Add and enter the field's details (Type and Name).

    4. To specify the entity primary key, select the relevant checkbox in the Key column of the Entity Fields table.

      To create a composite primary key, select the relevant primary key fields. The corresponding primary key class is generated together with 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

      End of the note.
    5. Select Field-based or Property-based access type for the entity.

  6. Choose Finish.

    The Developer Studio creates your entity class together with its getter and setter methods.

Specifying Object-Relational Mapping of 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 object/relational mapping of the entities’ primary keys explicitly, you can also generate primary keys automatically.

More information: Generated Primary Keys

End of the note.
Generating Tables from Entities (Forward Mapping)

Task

Steps

Generating Java Dictionary Tables

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

  2. In the context menu, choose   JPA Tools   Generate DDL  .

Generating Database Tables

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

  2. In the context menu, choose   JPA Tools   Generate DDL  .

  3. Fill out the required data:

    • Folder — the project folder that contains the entities used for table generation

    • File — the name of the SQL script file to be created

    • Generate — additional properties to be generated

  4. Choose Next, then choose Finish.

    The Developer Studio generates and opens the SQL 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 SQL 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 trigger 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 trigger a project clean build, choose   Project   Clean   in the main menu, then choose OK.