Create and configure a JPA 1.0 project
This tutorial shows you how to add JPA support to a dynamic Web project and then use JPA tools to create and configure entity beans from database tables.
This tutorial might require some optionally installable components. To ensure that you installed the appropriate optional components, see the System requirements list. This tutorial is divided into several exercises that must be completed in sequence for the tutorial to work properly
Learning objectives
In this tutorial, you will learn how to do the following things:
- Add JPA support to a dynamic Web project
- Create a connection to a database
- Create JPA entity beans from database tables
- Add primary keys to entity beans
- Configure a runtime database connection
- Create JPA manager beans for entity beans
Time required
This tutorial should take approximately 30 minutes to finish. If you explore other concepts related to this tutorial, it could take longer to complete.
Skill level
Intermediate
Audience
This tutorial is intended for users who want to become familiar with the some of the JPA tools provided in this product.
System requirements
To complete this tutorial, you need to have the following things:
- The WebSphere® Application Server, Version 7.0 Test Environment installed. You can also complete and run the tutorial on WAS, Version 6.1 Test Environment with the Feature Pack for EJB 3.0 installed.
- A clean workspace.
To use this tutorial, have an application server installed and configured. To verify that a server runtime environment is available, click
Window | Preferences, expand
Server, and then click
Runtime Environments. You can use this pane to add, remove, or edit installed server runtime definitions. You can also download and install support for a new server.
Lessons in this tutorial
- Lesson 1.1: Import the required resources
Before you begin, you need to import the required resources for this tutorial: a sample Derby database and a set of Web pages.- Lesson 1.2: Add JPA support to the project
In this lesson you will learn how to add JPA support to the dynamic Web project that you imported in the previous lesson.- Lesson 1.3: Create a connection to a database
In this lesson you will learn how to add a connection to a sample Derby database.- Lesson 1.4: Create entity beans from the database tables
In this lesson you will learn how generate JPA entity beans from tables in the sample Derby database that you connected to in the previous lesson.- 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.- Lesson 1.6: Create JPA manager beans
In this lesson you will learn how to generate JPA manager beans for the JPA entity beans that you created in the previous lessons. JPA manager beans are used to manage all of the data access related to your JPA entities, such as retrieving data through queries and updating your entities.- Lesson 1.7: Run the Web application to test the entities
In this lesson you will learn how to run the Web application on the server.