< Previous | Next >

 

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.

Before you begin, complete Lesson 1.4: Create entity beans from the database tables.

 

Configure the entity beans

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:

  1. In the Enterprise Explorer, right-click on one of the entity beans - Employee.java or Department.java - and select

    JPA Tools | Configure JPA Entities.

  2. On the Configure JPA Entities Page, ensure that both entities are selected. Click Next.

  3. On the Tasks Page, click

    Department. Ensure that

    Primary Key is selected, and then select

    deptno as the primary key.

  4. On the same page (Tasks), click

    Employee. Select

    empno as the primary key.

  5. 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:

  1. 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.

  2. 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.

< Previous | Next >