Creating a JPA entity

Use this procedure to create a JPA entity with the Create JPA Entity wizard:

  1. From the Navigator or Project Explorer, select the JPA project and then File > New > Other. The Select a Wizard dialog appears.

    Selecting the Create a JPA Entity Wizard

    The Select a Wizard dialog with Entity selected.

    Tip:

    You can also select the JPA perspective and then select File > New > JPA Entity.


  2. Select JPA > JPA Entity and then click Next. The Entity Class page appears.

    The Entity Class Page

    The Entity Class page of the Create a JPA Entity wizard.

    Complete the fields on the Entity Class page as follows:

    • Select the JPA project in the Project field.

    • In the Source Folder field, select, or enter, the location of the JPA project's src folder.

    • Select, or enter, the name of the class package for this entity in the Java Package field.

    • Enter the name of the Java class in the Class name field.

    • If needed, enter, or select a superclass.

    • If needed, complete the Inheritance section as follows (these properties are optional):

      • Accept the Entity option (the default) to create a Java class with the @Entity option.

      • Alternatively, select Mapped superclass (if you defined a super class).

      • Select Inheritance and then select one of the JSR 220 inheritance mapping strategies (SINGLE_TABLE, TABLE_PER_CLASS, JOINED).

      • Select Add to entity mappings in XML to create XML mappings in orm.xml, rather than annotations.

  3. Click Next to proceed to the Entity Properties page where you define the persistent fields for the entity.

    The Entity Properties Page

    The Entity Properties page of the Create JPA Entity wizard.

    Alternatively, click Finish to complete the entity.

  4. Complete the page as follows:

    1. If needed, enter a new name for the entity. Doing so results in adding a name attribute to the @Entity notation (@Entity(name="EntityName")).

    2. Accept Use default (the default setting) to use the default value for the name of the mapped table. Entering a different name results in adding the @Table notation with its name attribute defined as the new table (@Table(name="TableName")).


      Note:

      The Entity Name-related options are not available if you selected Mapped superclass on the Entity Class page


    3. Add persistence fields to the entity by clicking Add. The Entity Fields dialog appears.

      The Entity Fields Dialog

      The Entity Fields dialog.
    4. Select a persistence type from the Type list. You can retrieve additional types using the Browse function.

    5. Enter the field name and then click OK. Repeat this procedure for each field.

    6. If needed, select Key to designate the field as a primary key.

    7. Select either the Field-based access type (the default) or Property-based access type.

  5. Click Finish. Eclipse adds the entity to your project.

Related reference

Related tasks

Related concepts