Java Reference
In-Depth Information
4.3.7
Detached objects
The last of the seven ORM framework features is detached objects. Hibernate
objects are automatically detached when their Session is closed. The application
simply has to ensure that the objects that it needs are loaded before the Session is
closed. It can either eagerly load or navigate to the objects that it needs. Although
this sounds simple, as you will see in chapter 7 this can sometimes require extra
code in the façade, which encapsulates the business logic, to traverse the object
graph and force objects to be loaded. The application can reattach those objects
to a new Session and Hibernate will update the database with the changes.
Detached objects are a new feature in JDO 2.0 . There are three ways to detach
objects in JDO 2.0 . One option is to configure the PersistenceManager to behave
the same way as a Hibernate Session and to automatically detach objects when it
is closed. Another option is to serialize the JDO objects. The third option is to
explicitly detach objects by invoking the PersistenceManager . This option gives
the application the most control over which objects are detached because the
objects to detach are specified using a fetch group. The PersistenceManager
returns nonpersistent, detached copies of the specified objects. An application
can later reattach those objects to a different PersistenceManager . The JDO imple-
mentation will update the database with the changes.
4.3.8
Hibernate vs. JDO
As you can see, at a high level JDO and Hibernate provide an equivalent set of fea-
tures. Hibernate and the various JDO implementations are constantly improving, so
no single product has the lead for very long. Many of the controversial differences
are mostly inconsequential. Also, benchmarks such as TORPEDO [ TORPEDO ] show
that the performance is similar. So how do you choose between them?
Some important nontechnical issues differentiate JDO and Hibernate. From
the outset Hibernate has been an open source project, which has contributed
greatly to its incredible popularity. Budget-constrained organizations and other
open source projects have been able to download and use it. In comparison, JDO
is a standard with multiple implementations. Until recently the main JDO imple-
mentations were commercial implementations, whose licensing fees discouraged
some organizations from using JDO . However, today there are open source JDO
implementations such as JPOX [ JPOX ]. In addition, some organizations want to
avoid being dependent on a product that is available from a single source and
thus use a standards-based product that is available from multiple vendors.
 
 
 
 
 
Search WWH ::




Custom Search