Configuring JPA Properties

Workshop includes form editors to manage the JPA configuration file and includes wizards to add new content. The persistence.xml file defines a context for JPA. This context can include information about the underlying persistence provider, the database connection to use, vendor-specific properties to set, and so on. The persistence.xml file is typically located at this path in your project hierarchy:


Workshop provides a graphical interface for editing the persistence.xml file, as well as statement completion for those times when you want to edit the XML file directly. Graphical views on persistence.xml data also include a "source view" of the XML.

You start editing the persistence.xml file by right-clicking on JPA Configuration, then clicking Open.

You can also open the persistence.xml file by double-clicking it in AppXplorer.

Double-click the persistence.xml file to open its editor

Once it's open, you'll notice that the persistence.xml editor has four tabs:

Editing the Database Connection

Use the Connection tab to edit the database connection. Click Edit Connection Properties to display the Connection Properties dialog. There, you can edit the existing properties or grab properties from another connection to use instead.

Click Edit Connection properties to edit the database connection

By clicking Populate from existing connection, you can use a connection that you've already set up using DbXplorer. Note that if requested, Workshop will copy the database driver library and add it to your classpath, where it will be available to your persistence code.

Editing Mapping Class Information

You can add, remove and edit JPA entity beans using the Mappings tab. Click the Class Name link to view the source code for the selected mapped class.

Click Class Name to edit source code for the mapped class

Editing Persistence Properties

Use the Properties tab to edit configuration properties, such as vendor-specific information. In the following example, the EJB3 provider is Hibernate. Note that when you add a new property, you can browse from among the properties exposed by the provider.

Select from a list of provider properties

Editing the Source

Of course, you can always edit the persistence.xml source directly. When you're editing in the Source tab, you're helped by statement completion, as shown in the following illustrations.

Creating a new child element of <persistence-unit>.

Press control+space for XML completion

Adding a new <property> element.

Press control+space for attribute value completion

Related concepts

Generating JPA Mappings

Managing EJB3 Entity Relationships

Still need help? Post a question on the Workshop newsgroup.