Lesson 1.5: Add primary keys to the entities and configure the runtime
database connection
In this lesson you will learn how to add primary keys and named
queries to the entities that you generated in the previous lesson. You will
also learn how to configure a runtime connection to the Derby database.
JPA entities must include an @Id annotation to define the entity's
primary key. The JPA Tools can add the required primary key annotation for
you.
Perform the following steps to configure the entity beans:
In the Enterprise Explorer, right-click on one of the entity beans
- Employee.java or Department.java - and select JPA
Tools > Configure JPA Entities.
On the Configure JPA Entities Page, ensure that both entities are
selected. Click Next.
On the Tasks Page, click Department. Ensure
that Primary Key is selected, and then select deptno as
the primary key.
On the same page (Tasks), click Employee.
Select empno as the primary key.
Click Finish. The Configure
JPA Entities wizard adds the primary key annotations to the entities.
The
Set up Connections for Deployment wizard opens.
Configure the runtime connection
Perform the following steps to configure the runtime connection to
the Derby database:
If the Set up connections for deployment wizard did not automatically
open, right-click the project in the Package Explorer and click JPA Tools > Configure Project for JDBC deployment.
For Schema, select SAMP. Leave all other
selections at their defaults and click OK.
Lesson checkpoint
You have completed Lesson 1.5. In this lesson, you learned how
to add primary keys to your JPA entity beans. You also learned
how to configure a runtime connection to a database.