Databases Reference
In-Depth Information
Java Persistence API
Before the Java Persistence API ( JPA ) was introduced, we had the following three
alternative technologies which we could use to implement our persistence layer:
• The persistence mechanism provided by Enterprise JavaBeans ( EJB )
2.x specifications
• The JDBC API
• The third party object-relational mapping ( ORM ) frameworks
such as Hibernate.
This gave us some freedom when selecting the best tool for the job but as always,
none of these options were problem free.
The problem with EJB 2.x was that it was too heavyweight and complicated. Its
configuration relied on complicated XML documents and its programming model
required a lot of boilerplate code. Also, EJB required that the application be deployed
to a Java EE application server.
Programming against the JDBC API was rather simple and we could deploy our
application in any servlet container. However, we had to write a lot of boilerplate
code that was needed when we were transforming the information of our domain
model to queries or building domain model objects from query results.
Third party ORM frameworks were often a good choice because they freed us from
writing the unnecessary code that was used to build queries or to construct domain
objects from query results. This freedom came with a price tag: objects and relational
data are not compatible creatures, and even though ORM frameworks can solve most
of the problems caused by the object-relational mismatch , the problems that they
cannot solve efficiently are the ones that cause us the most pain.
The Java Persistence API provides a standard mechanism for implementing a
persistence layer that uses relational databases. Its main motivation was to replace
the persistence mechanism of EJB 2.x and to provide a standardized approach for
object-relational mapping. Many of its features were originally introduced by the
third party ORM frameworks, which have later become implementations of the Java
Persistence API. The following section introduces its key concepts and describes how
we can create queries with it.
 
Search WWH ::




Custom Search