# Generating entities from tables

Use this procedure to generate Java persistent entities from database tables. You must create a JPA project and establish a database connection before generating persistent entities. See "Creating a new JPA project" for more information.

To use the Generate Tables from Entities wizard:

1. Right-click the JPA project in the Project Explorer and select JPA Tools > Generate Entities from Tables.

   Generating Entities from Tables

2. On the Select Tables page of the Generate Entities from Tables wizard, select your database connection and schema.

   To create a new database connection, click Add connection.

   If you are not currently connected to the database, the Database Connection page appears. Select your database connection and schema, and click Reconnect.

   Select Tables

3. After selecting a schema, select the tables from which to generate Java persistent entities and click Next.

4. On the Table Associations page, select the associations to generate. You can specify to generate specific references for each association.

   To create a new association, click Add Association. Use the Create New Association wizard wizard to define the association.

   Table Associations

5. After editing the table associations, click Next.

6. On the Customize Default Entity Generation page, customize the mapping and class information for each generated entity.

   Customize Default Entity Generation

7. After customizing the mappings, click Next.

8. On the Customize Individual Entities page, review the mapping and class information for each entity that will be generated, then click Finish.

   Customize Individual Entities

Eclipse creates a Java persistent entity for each database table. Each entity contains fields based on the table's columns. Eclipse will also generate entity relationships (such as one-to-one) based on the table constraints. Figure: Generating Entities from Tables illustrates how Eclipse generates entities from tables.

Generating Entities from Tables

Related tasks

- Creating a new JPA project

Related reference

- Project Properties page – Entity Generation