Java Reference
In-Depth Information
Now that you have gotten an overview of
ORM
framework concepts in
JDO
and
Hibernate, let's look at how you can persist a domain model with
JDO 2.0
. As we
saw in chapter 4,
JDO
provides mostly transparent persistence for
POJO
s. Most
classes are unaware that they are persistent, and
JDO
supports the natural Java
programming style, including inheritance and recursive calls between objects. In
addition, because
JDO
can be used both inside and outside an application server,
you can develop and test business logic without having to first deploy it, which
accelerates development.
Of course, no technology is perfect;
JDO
has various shortcomings that must be
accommodated when you're developing an application. In this chapter we describe
the decisions you must make and the workarounds you must use when developing
with
JDO
. You will learn how to persist domain objects with
JDO
and implement
domain model repositories using Spring and
JDO
. This chapter also explains how
to optimize performance in a
JDO
application by using eager loading and caching.
We will use the Food to Go domain model developed in chapter 3 as an example.
For more detailed information about
JDO
, see
Java Data Objects
[Russell 2003].
5.1 JDO issues and limitations
JDO
is one of those technologies that has never received a huge amount of atten-
tion and hype. Although it was the first standard for Java transparent persistence,
it has always has been overshadowed by Hibernate. And, to make matters worse,
politics led the
EJB 3
expert group (
JSR-220
) to define a totally new standard for Java
transparent persistence instead of using
JDO
. But
JDO
is an excellent
ORM
technol-
ogy that has multiple commercial and open source implementations. The trend is
for those implementations to also support
EJB 3
, and as developers inevitably run
into
EJB 3'
s limitations (see chapter 10), it's likely they will find their way to
JDO
.
JDO
provides a flexible
ORM
mechanism that makes it straightforward to per-
sist a typical domain model. It supports all of the
ORM
features I described in
chapter 4, including relationships, embedded value objects, and inheritance. You
rarely need to make significant changes to your domain model in order to persist
it unless, of course, you are working with a legacy schema that has some quirky
features (such as denormalized columns). Making a domain model persistent is
usually only a matter of writing the
XML
metadata that defines how it maps to the
database schema and perhaps adding
ID
fields to classes.
You must, however, decide which kind of
JDO
object identity to use for each of
the classes in the domain model. In addition, you need to work around a limita-
tion of how interfaces are mapped to the database.
Search WWH ::
Custom Search