The Java Persistence API (JPA), part of the Java Enterprise Edition 5 (Java EE 5) Enterprise Java Beans (EJB) 3.0 specification, greatly simplifies Java persistence. It provides an object-relational mapping approach that allows you to declaratively define how to map Java objects to relational database tables in a standard, portable way that works both inside a Java EE 5 application server and outside an EJB container in a Java Standard Edition (Java SE) 5 application.
A JPA entity application can be packaged in a persistence archive, which is a JAR file that must have a JPA persistence descriptor file,
persistence.xml. One or more persistence units are configured in the
persistence.xml file. Each persistence unit must have a name. A named persistence unit provides a convenient way to specify a set of metadata files, and classes, and jars that contain all the classes to be persisted in a grouping.
When you use the Create Entities from Tables wizard to create the JPA entity, JDeveloper automatically creates a default persistence unit. In the Application Navigator, expand
Application Sources, then expand
persistence.xml to open the file in the overview editor. If necessary, click
Overview to switch to the overview editor. Use the overview editor for JPA persistence when you want to create new persistence units, and delete or edit existing ones in the
The default persistence unit generated by JDeveloper has the name
Project1 in the
persistence.xml file. Note that the default name of the persistence unit is derived from the project name.
The default persistence unit is configured to run inside a Java EE container, so you may want to use a name that identifies that purpose. To change the name of the persistence unit, in the overview editor select Project1 under Persistence Units and click . In the Rename Persistence Unit dialog, enter the new name.
A persistence unit that is configured to run inside a Java EE container must point a JTA data source that matches the database connection that was selected when using the wizard.
In the editor window for persistence.xml, click Source to switch to the XML editor.
persistence.xml file, one or more
<persistence-unit> entries are defined. Each
<persistence-unit> identifies a subset (possibly all) of the entities in the
.jar file, and associates metadata with this entity group.
The code for the
<persistence-unit> looks like this:
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...> <persistence-unit name="Project1"> <provider> org.eclipse.persistence.jpa.PersistenceProvider </provider> <jta-data-source> java:/app/jdbc/jdbc/FODDS </jta-data-source> <class> project1.ProductsBase </class> <properties> <property name="eclipselink.target-server" value="WebLogic_10"/> <property name="javax.persistence.jtaDataSource" value="java:/app/jdbc/jdbc/FODDS"/> </properties> </persistence-unit> </persistence>
In the example, you will not be using the default Project1 persistence unit. Instead you will be creating a new persistence unit that is configured to run outside the Java EE container, which you will do in the next cue card.
Copyright © 1997, 2009, Oracle. All rights reserved.false ,,,,,,,,,,,,,,,