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
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.
Note
The forward mapping tool does not create foreign key constraints on the database.
You have opened the JPA Development perspective.
You have associated your project to a Java Dictionary connection or to a database connection.
More information:
To use forward mapping, you must have specified the object-relational mapping of your entities.
Choose the (New) pushbutton.
Select
, then choose Next.Specify the details of the entity class:
Select the Project to be used for the entity.
(Optional) Select the Source folder of the project to store the entity.
Specify a Java package to contain the entity.
Enter a Class name of the entity.
If necessary, specify a Superclass.
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
(Optional) Select the Add to entity mappings in XML checkbox.
Choose Next.
Specify the details of the entity:
Enter an Entity Name.
To specify a custom table name for the entity, deselect the Use default checkbox and fill out the Table Name field.
To add a new field to the entity, choose Add and enter the field's details (Type and Name).
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
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
Select Field-based or Property-based access type for the entity.
Choose Finish.
The Developer Studio creates your entity class together with its getter and setter methods.
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 object/relational mapping of the entities’ primary keys explicitly, you can also generate primary keys automatically.
More information: Generated Primary Keys
Task |
Steps |
---|---|
Generating Java Dictionary Tables |
|
Generating Database Tables |
|