Java Reference
In-Depth Information
CHAPTER 2
n n n
Integrating and
Configuring Hibernate
C ompared to other Java persistence solutions, integrating Hibernate into a Java application is
easy. The designers of Hibernate avoided some of the more common pitfalls and problems with
the existing Java persistence solutions, and created a clean but powerful architecture. In prac-
tice, this means that you do not have to run Hibernate inside any particular J2EE container or
framework—Hibernate 3 only requires Java 2 Standard Edition ( J2SE), version 1.3 or greater,
although the new Annotations feature requires J2SE 5.0 (or later).
At first, adding Hibernate to your Java project looks intimidating—the distribution
includes a large set of libraries. To get your first Hibernate application to work, you have to set
up the database, the mapping files, the configuration, and your plain old Java objects (POJOs).
After you have done all that, you need to write the logic in your application that uses the
Hibernate session to actually do something! But once you learn how to integrate Hibernate
with your application, the basics apply for any project that uses Hibernate.
If you already have an application that uses Hibernate 2, the migration path from Hiber-
nate 2 to Hibernate 3 is easy. While Hibernate 3 is not completely backward-compatible, most
of the changes are additional features that you can integrate into your existing application as
you see fit. The Hibernate developers provided implementations of the core Hibernate 2
objects in Hibernate 3 with the Hibernate 2 methods for backward compatibility. We discuss
the differences between Hibernate 2 and Hibernate 3 in more depth in Appendix D.
One of the key features of Hibernate's design is the principle of least intrusiveness—the
Hibernate developers did not want Hibernate to intrude into your application more than was
necessary. This led to several of the architectural decisions made for Hibernate. In Chapter 1
you saw how Hibernate can be applied to solve persistence problems using conventional Java
objects. In this chapter, we explain some of the configuration details needed to support this
behavior.
The Steps Needed to Integrate and
Configure Hibernate
This chapter explains configuration and integration in detail, but for a quick overview, refer to
the following bulleted list to determine what you need to do to get your first Hibernate appli-
cation up and running. Chapter 3 leads you through the building of a pair of small example
11
Search WWH ::




Custom Search