Creating a Java Persistent Entity


This quick start shows how to create a new Java persistence entities. 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 EJB 3.0 Entity selected.
  3. On the Java Class page, enter a package name (such as quickstart.demo.model), class name (such as Address), and click Next. The Java Persistence Entity page of the Create New Java Persistence Entity wizard appears.

    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.

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.