Creating JPA entity beans from database tables

You can generate JPA entity beans from existing database tables (bottom-up mapping).

Before you begin

Prerequisite: You need to create a JPA project or enable JPA support in an appropriate project.

About this task

To generate entity beans from tables in a database:


  1. In the Package Explorer view, right-click the JPA project and select JPA Tools > Generate Entities from Tables.
  2. On the Database Connection page, select a database connection and schema. If you have not created the database connection, click the Add connections icon and follow the prompts in New Connection Profile wizard to complete the new connection.
  3. Select the tables from which you want to generate JPA entities.
  4. Click Next.
  5. In the Source folder field, the src folder of the JPA project is set by default. To specify another folder, click Browse and select it.
  6. In the Package field enter a package for the Java™ classes for the JPA entities.
  7. Optional: The entity name is the same as the table name by default. To change the entity name, click it and type the new name.
  8. Click Finish. The entities are generated in the source folder and package that you specified.
  9. Add a primary key (@Id annotation) to the entities:
    1. In the Package Explorer view, right-click one of the entities and select JPA Tools > Configure JPA Entities
    2. In the Configure JPA Entities wizard, select the entities that you created and then click Next.
    3. Click Primary Key.
    4. Click the entity to configure and then select the attribute to set as the primary key (@Id) for the entity.
    5. Repeat the previous step for any additional entities that need a primary key set.
  10. Optional: Add additional configuration details to the entities using the Configure JPA Entities wizard.
  11. Click Finish.