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:
Procedure
- In the Package Explorer view, right-click the JPA project
and select .
- 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.
- Select the tables from which you want to generate JPA entities.
- Click Next.
- 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.
- In the Package field enter a package
for the Java™ classes for the JPA entities.
- 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.
- Click Finish. The
entities are generated in the source folder and package that you specified.
- Add a primary key (@Id annotation) to the entities:
- In the Package Explorer view, right-click one of the
entities and select
- In the Configure JPA Entities wizard, select the entities
that you created and then click Next.
- Click Primary Key.
- Click the entity to configure and then select the attribute
to set as the primary key (@Id) for the entity.
- Repeat the previous step for any additional entities
that need a primary key set.
- Optional: Add additional configuration details to the entities
using the Configure JPA Entities wizard.
- Click Finish.