Java Reference
In-Depth Information
13.4.2. Describing the persistence module with persistence.xml
In chapter 9 we showed you how to group entities as a persistence unit and how to config-
ure that unit using persistence.xml. Now that you know how to package entities, it's time
to learn more about persistence.xml, the descriptor that transforms any JAR module into a
persistence module. It's worth mentioning that persistence.xml is the only mandatory de-
ployment descriptor that you have to deal with.
The following listing is an example of a simple persistence.xml that can be used with the
ActionBazaar application. It'll successfully deploy to any Java EE container that supports
JPA.
Listing 13.11. An example persistence.xml
Let's run through a quick review of the code. You define a persistence unit by using the
<persistence-unit> element . You can specify an optional factory class for the
persistence provider . If a persistence provider isn't specified, the default provider for
the Enterprise server will be used. You specify the data source for the persistence provider
so JPA knows how to connect to the database. If you have multiple persistence units in
a single archive, you may want to identify the entity classes that compose the persistence
unit . If you have entities in another JAR file that you want to include in this persistence
unit, use <jar-file>
with a path to the JAR that's relative to this JAR file. Option-
ally, you can specify vendor-specific configuration using the properties element
.
Search WWH ::




Custom Search