Java Reference
In-Depth Information
Spring framework provides
AOP
interceptors that call the transaction manage-
ment
API
s on behalf of the application.
In addition,
JDO
and Hibernate provide
JTA
integration. A Hibernate
Session
or
JDO
PersistenceManager
that is opened within a
JTA
transaction will automati-
cally participate in the transaction.
4.3.5
Lazy and eager loading
By default,
JDO
and Hibernate load objects lazily, but you can configure them to
load objects eagerly. The details differ by framework but they provide roughly
equivalent functionality.
Configuring eager loading in JDO
You configure eager loading in
JDO
by using fetch groups. A
JDO
fetch group
specifies a graph of interconnected objects and is defined in the
XML
mapping
document. When an application loads an object or executes a query, it can iden-
tify the objects to eagerly load by specifying one or more active fetch groups.
You can use fetch groups to configure eager loading in one of two ways:
Statically configure a relationship to be always loaded.
■
Activate particular fetch groups at runtime to dynamic control which rela-
tionships to eagerly load.
■
For more information on
JDO
fetch groups, see chapter 5.
Configuring eager loading in Hibernate
Hibernate provides two ways to configure eager loading. You can specify in the
O/R
mapping which relationships should be eagerly loaded. This approach is
useful when a relationship is always traversed by the application. Alternatively,
you can use a Hibernate query with what is termed a
fetch join
to specify which
objects should be eagerly loaded by a query. By using different queries at
runtime, you can dynamically control which objects are eagerly loaded when
handling a request. See chapter 6 for more information about Hibernate and
eager loading.
4.3.6
Object caching
Hibernate and
JDO
cache objects, albeit with some minor differences. By default,
Hibernate caches objects in the
Session
for the lifetime of the session, which can
span multiple transactions, and
JDO
caches objects in the
PersistenceManager
for
the duration of a transaction. However, this difference is not usually that important
Search WWH ::
Custom Search