Java Reference
In-Depth Information
domain model using inheritance, encapsulation, and polymorphism to enable complex be-
havior and enforcement of business rules in an application. Table 9.1 summarizes some of
the overt mismatches between the object and relational worlds.
Table 9.1. Impedance mismatch: differences between the object and relational worlds
Domain model (Java)
Relational model (database)
Objects, classes
Tables, rows
Attributes, properties
Columns
Identity
Primary key
Relationship/reference to other entity
Foreign key
Inheritance/polymorphism
Doesn't exist
Methods
Indirect parallel to SQL logic, stored procedures, triggers
Code is portable
Not necessarily portable, depending on vendor
For the remainder of this chapter, we'll look at how this impedance mismatch may be over-
come, specifically using JPA as a translator between the relational and domain models.
We'll look at how JPA maps relational database table rows and columns into Java object
domain models.
9.1.2. Relationship between EJB 3 and JPA
Before we jump into JPA, let's look at its history and its relationship with EJBs. When
Java EE 5 was released, the EJB container was completely rearchitected, moving to a light-
weight POJO, annotation, and convention-over-configuration design. With EE 5 came the
first introduction to the Java Persistence API. At the time, JPA was part of the EJB spe-
cification. This made sense because at that time JPA was tied heavily to EJBs, which are
primarily responsible for enforcing business rules and maintaining data integrity for your
applications. But as the JPA specification grew and become more feature-rich, it was even-
tually rolled into its own Java specification request (JSR).
JPA version 2.1 is specified in JSR-338 and is available at the Java Community Process
website at http://jcp.org/en/jsr/detail?id=338 . The exciting part of having its own specific-
ation is that JPA has been decoupled from the Java Enterprise Edition (Java EE) and can
now be easily used within the Java Standard Edition (Java SE) applications as well. In other
words, you no longer need to have a JAVA EE server or EJB container to take full advant-
age of the power that JPA brings to the data access layer of your application. This opens
JPA for use in applications that it couldn't be used in before. But before using JPA in your
 
Search WWH ::




Custom Search