Java Reference
In-Depth Information
What is required for JPA?
The following components are required for JPA:
• A relational database. We shall be using the Oracle database 10 g or XE. But,
any database may be used. The databases supported by EclipseLink JPA shall
be discussed in the next section.
• Entity classes. An Entity class is just a POJO annotated with the @Entity
annotation:
@Entity
public class Catalog implements Serializable {
...}
We shall discuss in a later chapter why the class is implementing the Serial-
izable interface.
• A persistence.xml configuration file. The persistence.xml file specifies
the target database, the target server, the entities that are mapped to the
database, and other properties, which we shall discuss in a later section.
• Metadata. Object relational mapping in EJB 3.0 is implemented using
metadata, which may be specified using metadata annotations or in an object
relational mapping XML file that conforms to the http://java.sun.com/
xml/ns/persistence/orm_1_0.xsd XML Schema. If metadata annotations
are used an XML mapping file is not required, but if the XML mapping file
is included, in addition to the metadata annotations, the XML mapping file
overrides the metadata annotations. Metadata annotations are easier to use
as they are specified inline with the source code not requiring source code
context replication. XML mapping is complex and requires source code
context replication of where the metadata applies. For their ease of use and
no major disadvantage other than the coupling of the source code with the
metadata, we shall use metadata annotations in this topic.
• Persistence provider. The persistence provider provides the JPA
implementation. Oracle Fusion Middleware 11 g uses the EclipseLink JPA
persistence provider. The persistence provider manages the object relational
mappings of entities and entity relationships.
• Entity manager. An entity manager is required to manage the entities. In the
next section, we discuss the entity managers.
Types of entity managers
There are two types of entity managers available, depending on the Java
environment in which the entity manager is obtained.
 
Search WWH ::




Custom Search