Show TOC Start of Content Area

Procedure documentation Creating Entities and Generating Database Tables  Locate the document in its SAP Library 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 the 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 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.


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.


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


You have:

      Opened the JPA Development perspective

      Connected your project to the Java Dictionary or to a native database

More information:

Creating Connections to the Java Dictionary

Creating Database Connections


1. Create the Entities.


       1.      Select File New Other from the main menu.

       2.      Select EJB EJB 3.0 JPA Entity, then choose Next.

       3.      Specify the required data:

                            a.      Project to store the entity

                            b.      Java package to contain the entity

                            c.      Class name of the entity

       4.      If necessary, specify superclass and inheritance details.

       5.      Choose Next.

       6.      Specify the additional elements of the entity.

                            a.      To specify a custom name for the database table used for mapping of the entity, deselect the Use default checkbox and enter the custom name in the Table name field.

                            b.      To add entity fields, choose Add and enter Type and Name.

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

To create a composite primary key, select the relevant primary key fields. The corresponding primary key class is generated together with the entity.


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

       A primitive Java type

       A primitive wrapper type




                            d.      Select Field-based or Property-based access type for your entity.

       7.      Choose Finish.

The SAP NetWeaver Developer Studio creates the entity together with its getter and setter methods.

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 SAP NetWeaver Developer Studio help content.


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

More information:



Cascading Entity Manager Operations

3. Generate Tables from the Entities.

The following table shows the necessary steps to generate tables from entities, depending on the destination:



Generate Java Dictionary tables



       1.      In the Package Explorer, select the project you are using for your entities.

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

       3.      Choose OK.

Generate database tables



       1.      In the Package Explorer, select the project you are using for your entities.

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

       3.      Fill in the required data:

       Folder – the project folder that contains the entities used for table generation

       Filethe name of the SQL file to be generated

       (Optional) Generate additional properties to be generated

       4.      Choose Next, then choose Finish.

The SAP NetWeaver Developer Studio opens the generated SQL script file in the standard SQL editor.

       5.      If necessary, specify the details of the connection profile you are using to connect to your database:

       Type of the connection profile

       Name of the connection profile

       Databasethe name of your database

       6.      In the context menu of the SQL code, 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 schema, and to perform a clean build of the project that contains the entities.

       7.      Refresh the database schema.

                            a.      In the Data Source Explorer, select the database schema you are using for your application tables.

                            b.      In the context menu, choose Refresh.

       8.      To trigger a clean build of your project, choose Project Clean in the main menu, then choose OK.


End of Content Area