Home

 

Creating a JPA project

We generate the JPA entities from the ITSOBANK database into a JPA project. JPA projects are basically utility projects that hold the Java classes, which represent the JPA entities.

To create the JPA project, perform these steps:

In the Java EE perspective, Enterprise Explorer view, right-click and select New Æ Project.

In the New Project wizard, select JPA Æ JPA Project, and click Next.

In the New JPA Project wizard, JPA Project page (Figure | 2-1):

Type RAD75JPA as Project name.
For Target Runtime, select WebSphere Application Server v7.0.
For Configuration, select Utility JPA project with Java 5.0.
Clear Add project to an EAR.
Click Next.

Figure 12-1 New JPA Project

In the New JPA Project wizard, JPA Facet page (Figure | 2-2):

For Platform select RAD JPA Platform.
For Connection select ITSOBANKderby. If the connection is not active, click Connect.
Clear Override default schema from connection (ITSO is the schema).
For JPA implementation, select Use implementation provided by the server runtime.
For persistent class management select Discover annotated classes automatically.
Select Create orm.xml.
Click Finish.

Figure 12-2 JPA Facet

When prompted to switch to the JPA perspective, click Yes.

The RAD75JPA project is created.

Two files are created in the src/META-INF folder:

An empty orm.xml file that can be used for explicit mapping of entities to database tables.
A persistence.xml file that defines a persistence unit (RAD75JPA):

<?xml version="1.0" encoding="UTF-8"?>

<persistence version="1.0"

xmlns="http://java.sun.com/xml/ns/persistence"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/persistence

http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

<persistence-unit name="RAD75JPA">

</persistence-unit>

</persistence>

This file holds the persistent entity classes.

ibm.com/redbooks