Mapping an entity


This quick start shows how to map fields in a Java persistent entity. Before beginning, add the following fields to the Address class:

private Long id;
private String city;
private String country;
private String stateOrProvince;
private String postalCode;
private String street;

Eclipse updates the Address entity in the Persistence Outline view to show its fields:

Address Entity and Fields

This figure shows the Address entity and its fields in the Persistence Outline view.

You will also need to add the following columns to the ADDRESS database table:

NUMBER(10,0) ADDRESS_ID (primary key)
VARCHAR2(80) PROVINCE
VARCHAR2(80) COUNTRY
VARCHAR2(20) P_CODE
VARCHAR2(80) STREET
VARCHAR2(80) CITY

Now we are ready to map each fields in the Address class to a column in the database table.

  1. Select the id field in the Persistence Outline view.

  2. In the Persistence Properties view:

    • For the Map As field, select ID

    • For the Column field, select ADDRESS_ID.

    Persistence Properties View for addressId Field

    This figure shows the Persistence Properties view for the id field.

    Eclipse adds the following annotations to the Address entity:

    @Id
    @Column(name="ADDRESS_ID")
    
    
  3. Map each of the following fields (as Basic mappings) to the appropriate database column:

    Field Map As Database Column
    city Basic CITY
    country Basic COUNTRY
    postalCode Basic P_CODE
    provinceOrState Basic PROVINCE
    street Basic STREET

Notice that Dali will automatically map some fields to the correct database column (such as the city field to the CITY column) if the names are identical.

Refer to the Dali basic tutorial to build and deploy a complete project with Java persistence entity mappings.