Welcome!

Java Authors: Robert Demmer, Maureen O'Gara, Tim Negris, Max Katz, Peter Silva

Related Topics: Java, XML, Oracle

Java: Article

Exploring Persistence Settings - Part 5

Explore the persistence.xml file for your JPA web project

In Part 4 I discussed the Oracle Enterprise Pack for Eclipse and how it allows you to view, create, and manage JPA entity relationships. The Entity Editor provides a centralized view of all entity relationships, allows you to modify entity properties, and allows you to navigate between the object model, mapping associations, and database schema layers.

In Part 5, I will explore persistence settings. The persistence.xml file defines the context for JPA persistence. In this step, you will use the JPA Persistence Configuration Editor to explore the persistence.xml file for your JPA web project.

In this step, you will:

Use the JPA Persistence Configuration Editor to view the persistence configuration file
The JPA Persistence Configuration Editor provides a graphical interface that allows you to modify connection information, mapped classes, and JPA properties that are managed by your persistence.xml file. Optionally, you can also use the editor to edit the persistence.xml source file.

  • From the Project Explorer, open the JPA Persistence Configuration Editor by right-clicking persistence.xml and selecting Open. This will open the persistence.xml configuration file in the JPA Persistence Configuration Editor (see Figure 1).

  • You can also open the persistence.xml file by double-clicking it in Project Explorer. The persistence.xml file is located at this path in your project hierarchy: web\WEB-INF\src\java\META-INF (see Figure 2).

  • The JPA Persistence Configuration Editor is organized in four category tabs:
    • Connection - Edit the database connection information
    • General - Edit information about managed classes and the persistence provider unit
    • Properties - Edit vendor-specific and general properties
    • Source - Edit the persistence.xml source directly (see Figure 3)

View the connection properties
The Connection tab of the persistence.xml editor displays the current connection properties and allows you to modify the existing connection if you use a JDBC Datasource. If you choose to instead embed the connection properties directly in persistence.xml, you can use the Properties tab to edit them. This tutorial embeds the properties directly.

  • To view or update the Open JPA connection information, click the Properties tab of the persistence.xml editor (see Figure 4).

View JPA mapping files
You can use the General tab to view and modify mapped classes.

  • Click the General tab in the JPA Configuration Editor. The Managed Classes section of the editor displays the list of managed classes in the persistence unit.
  • To edit the JPA entity beans, select a mapped class from the list and click Open to view the source code for the selected mapped class.
  • The editor also allows you to add a new mapped class by clicking Add... and browsing to the class (see Figure 5 and 6).

In Step 6 I will demonstrate how to generate Spring ORM classes.

More Stories By Pieter Humphrey

Pieter Humphrey has been at Oracle (by way of BEA Systems) for 7+ years, working in development, marketing, sales, and developer relations to advance Java technology in the enterprise. He ran the dev2dev community at BEA and continues to with work with Oracle OTN and Eclipse Foundation communities. His current role is focused on application development tools like Oracle Enterprise Eclipse Pack, Oracle Workshop for WebLogic, JDeveloper, TopLink and the ADF framework, and is a frequent speaker at industry events and workshops.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.