Java Reference
In-Depth Information
Feature
Single-table
Joined-tables
Table-per-class
• Mandatory
columns may be
nullable.
• The table grows
when more sub-
classes are added.
properties. Mapped tables are
normalized.
Uses discriminator column? Yes
Yes
No
SQL generated for retrieval
of entity hierarchy
SELECT clause joining mul-
tiple tables.
One SELECT for each sub-
class or UNION of SELECT.
Simple SELECT.
Single INSERT or UPDATE
for all entities in the hier-
archy.
Multiple INSERT, UPDATE:
one for the root class and one
for each involved subclass.
One INSERT or UPDATE
for every subclass.
SQL for insert and update
Polymorphic relationship
Good
Good
Poor
Polymorphic queries
Good
Good
Poor
9.6. Summary
This concludes our introduction to JPA. Remember, JPA is rich in features and is now
covered in its own 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 ) . We encourage you
to consider this chapter a brief introduction and to explore the many additional features of
JPA on your own.
We started by explaining the challenges of mapping database data to a Java domain model.
An impedance mismatch exists because each technology has completely separate views of
data (which in a number of ways contradict each other), so a translator, JPA, is needed
to bridge this gap. We continued by introducing you to a simple Java domain model for
ActionBazaar. You gave names to the entities and defined the relationships between the
entities. After this, we started exploring the rich JPA annotation set for configuring JPA
to get data in and out of the database and to define relationships among data. We looked
at @Entity to mark an object as an entity JPA should manage; @Table and @Sec-
ondaryTable to map entities to database tables; @Column , @Transient , @Tempor-
al , and @Enumerated to map entity properties to table columns; @Id , @IdClass ,
and @EmbeddedId to identify primary keys; and @GeneratedValue for generating
primary keys. Next, you saw how the relationships between entities are defined by looking
Search WWH ::




Custom Search