Creating a Java persistent entity


This quick start shows how to create a new Java entity with persistence. We will create an entity to associate with a database table.

  1. Right-click the project in the Package Explorer and select New > Other. The Select a Wizard dialog appears.

  2. In the Select a Wizard dialog, select Java Persistence > Entity and click Next. The Java Class page of the Create New Entity wizard appears.

    Selecting the Java Persistence Entity Wizard

    Select a Wizard dialog, with Java Persistence > Entity selected.
  3. On the Java Class page, enter a package name (such as quickstart.demo.model), class name (such as Address), and click Finish.

    Creating a Java Class

    This figure shows the Java Class dialog for the new quickstart.demo.model.Address class.

Eclipse adds the new entity to the project and adds the @Entity annotation to the class.

Address Entity

This figure shows the Java editor with the Address entity.

Eclipse also displays the Address entity in the Persistence Outline view:

Address Entity

This figure shows the Address entity in the Persistence Outline view.

After creating the entity, you must associate it with a database table.

  1. Select the Address class in the Explorer view.

  2. In the Persistence Properties view, notice that Dali has automatically associated the ADDRESS database table with the entity because they are named identically.

    Persistence Properties View for Address Entity

    This figure shows the Table selection for the Address entity in the Persistence Properties view.

Now that you have created a persistent entity, you can continue with Mapping an entity to map the entity's fields to columns on the database table.