Java Reference
In-Depth Information
main model. The translator in this case will be JPA. It's the responsibility of JPA to move
data back and forth between your database and Java domain model.
O/R mapping is a complicated job. Every possible database structure needs to be able to be
mapped to every possible Java domain model. This mapping problem is commonly known
as the impedance mismatch. In the next section, we'll begin a review of JPA by explaining
the impedance mismatch and then continue on with the rest of the chapter to explain the
key features JPA uses to solve it.
9.1.1. Impedance mismatch
The term impedance mismatch refers to the differences in the OO and relational paradigms
and difficulties in application development that arise from these differences. The persisten-
ce layer, where the domain model resides, is where the impedance mismatch is usually the
most apparent. The root of the problem lies in the differing fundamental objectives of both
technologies.
When a Java object holds a reference to another object, the actual referred object isn't (typ-
ically) copied over into the referring object. In other words, Java accesses objects by ref-
erence and not by value. If this weren't the case, you'd probably store the identity of a
referred object (perhaps in an int variable) instead and dereference the identity when ne-
cessary. On the other hand, relational databases have no concept of accessing objects by
reference. Relational databases use identities almost exclusively. These identities point to
where the real data resides, and database queries use the identities to dereference the data
when needed.
Java also offers the luxury of inheritance and polymorphism that doesn't exist in the rela-
tional world. Lastly, Java objects include both data (instance variables) as well as behavior
(methods). Databases tables, on the other hand, inherently encapsulate data in rows and
columns but don't have behavior.
These differences highlight the impedance mismatch. Both relational databases and Java
domain models attempt to solve the same conceptual problem, but they do so using com-
pletely different languages. An experienced database administrator (DBA) will efficiently
store data in appropriately normalized database tables using primary keys, foreign keys,
and constraints to maintain data integrity. An experienced Java developer will create a rich
Search WWH ::




Custom Search