Show TOC

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

 

This procedure describes how you create database tables manually and use the entity generation function (also called “backward mapping”).

If you are using the system database, you have to define the tables in the Java Dictionary.

More information about Java Dictionary: Providing Java Dictionary Tables and Data Types

If you want to create the database tables in a different schema than the system one, you have to follow the steps described in the relevant database product documentation.

If your database model is not completely defined, you have to specify the generated entities' object-relational mapping additionally.

Caution Caution

The SAP implementation of JPA expects that there are no foreign key constraints on the database. If foreign key constraints exist, the behavior is undefined.

End of the caution.

Prerequisites

You have:

Procedure

  1. Create the database tables.

    • Create the database tables in the Java Dictionary.

      More information: Creating Tables

    • Create the database tables in a native database.

      For a description of the tools and procedures, refer to the corresponding database product documentation.

      More information about creating database tables in SAP MaxDB: Creating Your Own Application Tables in the Database

      Note Note

      You can also create your database tables using the SQL Development Tools of the Developer Studio. For more information, refer to the “Data Tools Platform User Guide”, provided by the SAP NetWeaver Developer Studio help content.

      End of the note.
  2. Generate entities from Java Dictionary or database tables.

    1. In the Project Explorer, select the project where you want to store the entities to be generated.

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

    3. Select a Connection and a Schema.

    4. Choose Next.

    5. Complete the Source Folder and Package fields.

      • Source Folder — the folder to contain the Java source files

      • Package — the name of the package to contain the entities.

    6. To list the entity classes as part of the persistence unit in the persistence.xml, select the Synchronize Classes in persistence.xml checkbox.

    7. Select the tables that you want to generate entities from, then choose Finish.

  3. To complete the application data model, finalize the object-relational mapping of the generated 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.

    More information:

    Relationships

    Inheritance

    Cascading Entity Manager Operations