Java Reference
In-Depth Information
4.3 Overview of JDO and Hibernate
Now that we have looked at the key features of an
ORM
framework, let's examine
Hibernate and
JDO
, which are two popular
ORM
frameworks that provide a rich
set of features. Hibernate is a widely used open source project. Hibernate 1.0 was
released in 2002, and as of this writing, Hibernate 3.1 is in beta.
JDO
is a standard
(
JSR-012
and
JSR-243
) that has both commercial and open source implementa-
tions. The
JDO 1.0
specification was also released in 2002, and as of this writing,
the
JDO 2.0
specification is nearing release.
In this section I review what Hibernate and
JDO
provide in terms of the seven
ORM
framework features I described in the previous section. Chapter 10 describes
the
O/R
mapping capabilities in
EJB 3
.
4.3.1
Declarative mapping between the object model
and the schema
JDO
and Hibernate define the
O/R
mapping using
XML
documents. Historically,
Hibernate provided a much richer set of
O/R
mapping features than most of the
early
JDO
implementations. However, over time
JDO
implementations improved
considerably.
JDO 1.0
implementations developed a rich set of
ORM
extensions, and
the newer
JDO 2.0
standard incorporated many of those extensions and now pro-
vides a rich object/relational mapping. As a result, today Hibernate and
JDO
are
fairly comparable in terms of the object/relational mapping features they provide.
One key difference between
JDO
and Hibernate is that
JDO
only supports
mapping fields to the database schema whereas Hibernate supports mapping
either fields or JavaBean-style properties. Usually, you only need to map fields,
but occasionally it is useful to map JavaBean properties instead. For example, the
getter can calculate the value that is stored in the database, and a setter can ini-
tialize nonpersistent fields.
JDO and Hibernate let you map your objects to an existing schema. Alterna-
tively, Hibernate and many
JDO
implementations can generate the database
schema from the
O/R
mapping. This is extremely useful because it eliminates the
need to maintain the data definition language (
DDL
) files that define the data-
base schema. It also increases the portability of the application because Hibernate
and
JDO
will generate the database-specific
DDL
. Later I describe how this can be
useful when testing with an in-memory database. However, even though this fea-
ture is extremely convenient you cannot always use it. For example, you might
have to use database-specific schema definition features that are not supported by
Search WWH ::
Custom Search