Java Reference
In-Depth Information
Hibernate is an extremely popular open source, ORM framework. It provides
mostly transparent persistence for POJO s as well as a rich set of ORM options.
Hibernate can run inside an application server or in a two-tier environment
(which accelerates development by enabling Hibernate-based business logic to be
developed and tested outside of the application server). However, like every tech-
nology Hibernate has its strengths and weaknesses. In this chapter, you will learn
how to leverage Hibernate's strengths and how to work around its weaknesses.
We describe how use Hibernate 3.0 to persist a domain model using the Food
to Go domain model from chapter 3 as an example. You will learn how Hibernate
implements each of the main ORM concepts described in chapter 4, including its
mapping features and API . We describe how to map the domain model to a data-
base schema and the changes that we must make to accommodate Hibernate's
limitations. You will learn how to implement domain model repositories with the
Hibernate API and the Spring framework. We also explain how to effectively test a
Hibernate-based persistence layer.
For more detailed information about Hibernate, see Hibernate in Action [Bauer
2005].
6.1 Hibernate ORM issues
Hibernate is the de facto standard for Java transparent persistence. This is
because it's free, it's well documented, and it works. You can download it and
install it without having to make a case for spending thousands of dollars in devel-
opment licenses. The excellent documentation means that getting started is rela-
tively painless. Also, other than a few quirks here and there, it works as advertised.
As a result, Hibernate is widely used.
Because Hibernate provides a powerful and flexible ORM mechanism, persist-
ing a typical domain model is mostly straightforward. However, there are still some
Hibernate-specific issues to resolve. In this section and the next one, we describe
those issues and explore the different options. Let's first look at some of the deci-
sions you must make when defining the O/R mapping for a domain model.
6.1.1
Fields or properties
A persistence framework such as Hibernate must read and write the object's state
when it transfers the object to and from the database. An object's state consists of
the values of its fields, but sometimes it is useful to encapsulate the state with
Java Bean-style properties. Hibernate, unlike JDO , can map either fields or
Java Bean-style properties to the database schema. If the O/R mapping is defined in
 
 
 
 
Search WWH ::




Custom Search