Previous Next vertical dots separating previous/next from contents/index/pdf

Adding Java Persistence API (JPA) Support

In order to use JPA, you need to be working within a project that supports it — in other words, a project that includes the required libraries. You can add this support in one of two ways:

Adding JPA Support to a New Project

When you create a new web application project, the wizard will prompt you with the following dialog. Select the JPA facet and the Hibernate facet if needed.

As you continue to click Next through the project creation wizard, you will be prompted for additional EJB3 parameters.

If you selected the Hibernate facet, you will be prompted for Hibernate settings.

Finally, you will be prompted to choose an JPA provider from the dropdown.

Note: Workshop Studio uses the provider information to recognize the provider-specific database connection properties in the Entities Editor and to update the persistence.xml file with the connection properties when generating entities from schema. It is also used to provide custom editing of the provider properties in the persistence.xml file. For more information, see Configuring JPA Properties.

Select the EJB3 persistence provider

You can choose Generic JPA or support offered by BEA Kodo or Hibernate. Continue through the wizard to finish creating your web application project.

Adding JPA Support to an Existing Project

You can add JPA support to a web application project you've already created by editing the project's properties. In the project's properties dialog, in the left panel, click Project Facets; in the right panel, click the Add/Remove Project Facets button.

Click Add EJB3 Persistence Capabilities to add them to an existing project

This displays the Select Project Facets dialog where you can choose to add the JPA facet and optionally the Hibernate facet.

If you select Hibernate, the next screen allows you to set Hibernate parameters.

You also need to choose an JPA provider. Workshop Studio provides Hibernate and Kodo by default, but you can also choose another. Note that if you choose (Generic), you'll need to ensure that your server includes the libraries needed to support your provider.

Select an EJB3 persistence provider

Click Finish to update your project with JPA support. If you've added EJB3 support but no entities — for example, an existing persistence.xml file you selected has no entities defined — the entities editor added to your project will look something like the following. For more information on using the links in the editor to create entities, see Creating JPA Mappings from Schema and Annotating Existing Classes for JPA.

Use links in the empty Entities Editor to create entities

Related concepts

Configuring JPA Properties

Generating JPA Mappings

Managing EJB3 Entity Relationships

 

Skip navigation bar   Back to Top