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 JPA Structure view to show its fields:

Address Entity and Fields

Address entity and its fields in the JPA Structure 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 JPA Details view.

  2. In the JPA Details view:

    • For the Map As field, select Id

    • For the Column field, select ADDRESS_ID.

    JPA Details View for addressId Field

    JPA Details 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 map a complete object model using basic and relational mappings.