Java Reference
In-Depth Information
1.3.1. Entities and the Java Persistence API
EJB 3.1 saw JPA 2 moved from an EJB 3 API to a completely separate Java EE specifica-
tion. But JPA has some specific runtime integration points with EJB because the specific-
ations are so closely related. We'll say just a few things about JPA here because we have
chapters dedicated to it.
Persistence is the ability to have data contained in Java objects automatically stored into a
relational database like Oracle database, SQL server database, and DB2 database. Persist-
ent objects are managed by JPA. It automatically persists Java objects using a technique
called object-relational mapping (ORM). ORM is the process of mapping data held in Java
objects to database tables using configuration or declaratively using annotations. It relieves
you of the task of writing low-level, boring, and complex JDBC code to persist objects into
a database.
An ORM framework performs transparent persistence by making use of ORM metadata
that defines how objects are mapped to database tables. ORM isn't a new concept and
has been around for a while. Oracle TopLink is probably the oldest ORM framework in
the market; open-source framework JBoss Hibernate popularized ORM concepts within
the mainstream developer community. Because JPA standardizes ORM frameworks for the
Java platform, you can plug in an ORM product like JBoss Hibernate, Oracle TopLink, or
Apache OpenJPA as the underlying JPA “persistence provider” for your application.
JPA isn't just a solution for server-side applications. Persistence is a problem that even a
standalone Swing-based desktop application has to solve. This drove the decision to make
JPA 2 a cleanly separated API in its own right that can be run outside an EJB 3 container.
Much like JDBC, JPA is intended to be a general-purpose persistence solution for any Java
application.
Entities
Entities are the Java objects that are persisted into the database. While session beans are the
“verbs” of a system, entities are the “nouns.” Common examples include an Employee
entity, a User entity, and an Item entity. Entities are the OO representations of the ap-
plication data stored in the database. Entities survive container crashes and shutdown. The
ORM metadata specifies how the object is mapped to the database. You'll see an example
Search WWH ::




Custom Search