You can generate JPA entity beans from existing database
tables (bottom-up mapping).
Before you begin
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 Generate Custom Entities 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.
- Create, edit, or delete table associations by using the
proper icons. Click Next.
- Optionally, you can customize aspects of the entities to
be generated, change the package and class, and add interfaces. Click Next.
- In the Customize Individual Entities page,
you can select tables and columns and set up the mapping values for
each one. Click Finish. The entities
are generated.
- 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
before exiting this wizard.
- Click Finish.