Show TOC Start of Content Area

Procedure documentation Mapping Entities to Database Tables  Locate the document in its SAP Library structure

Use

You use this procedure to map entities to database tables. The JPA specification defines two access types for entities:

      Field-based access

With field-based access, the persistent properties of the entity are accessed directly. To map persistent properties for field-based access, you annotate the class properties, that is, entity fields.

      Property-based access

With property-based access, persistent properties are accessed using getter and setter methods. To map persistent properties for property-based access, you annotate the getter methods.

Prerequisites

You have opened the Java Persistence perspective.

More information: Java Persistence Perspective

Procedure

Mapping Entities to Database Tables

 

...

       1.      Select the entity in the Package Explorer.

       2.      Choose Open from the context menu.

       3.      Select the entity in the Persistence Outline. The properties of the entity are listed in the Persistence Properties view.

       4.      If you wish to map the entity to a specific database table, enter the table name in the Name field of the General tab. If you leave the field with the default setting, the entity is mapped to a table with the same name as the entity.

This graphic is explained in the accompanying text

Mapping Entity Fields to Columns

...

       1.      Select an entity field in the Persistence Outline.

       2.      If you wish to map the field to a specific table column, enter the column name in the Name field. If you leave the Name field with the default setting, the entity field is mapped to a column with the same name as the entity field. Thus, you use field-based access.

More information about property-based access: Accessing the Persistent State

This graphic is explained in the accompanying text

Mapping the Entity Primary Key

...

       1.      Select the entity field you wish to map as the primary key in the Persistence Outline.

       2.      Choose Map As Id in the Persistence Properties view. The SAP NetWeaver Developer Studio updates the source code of the entity field with the @Id annotation.

This graphic is explained in the accompanying text

Note

You can also generate primary keys automatically.

More information: Generating Primary Keys

Note

The object-relational mapping tool in the SAP NetWeaver Developer Studio is provided by the open-source Dali project, version 0.5. If you use the tool to generate DDL statements from existing persistent entities, be aware of the following limitations:

    Important properties of the @Column annotation (for example, length, nullable) are ignored.

    Some persistence annotations are ignored (for example, @Lob, @Temporal, @Enumerated, @DiscriminatorColumn).

    Arrays (for example, byte[] and java.lang.Byte[]) are mapped to VARCHAR(255).

    The precision and scale of the numeric data types are defaulted to 0.

    The length of the data types is defaulted to 255.

    Only bi-directional One-to-Many relationships are supported.

    Only uni-directional Many-to-Many relationships are supported.

    Integral ID values Table is not generated.

    Entity inheritance is not supported.

    Only field level annotations are considered.

End of Content Area