More Books
Hibernate: A J2EE Developer's Guide
Hibernate: A J2EE™ Developer's Guide
Table of Contents
Copyright
Acknowledgments
About the Author
Preface
Required Skills
Roadmap
Chapter 1. Overview
Why Object/Relational Mapping?
What Is Hibernate?
Comparing JDBC to Hibernate
Hibernate's Mapping System
Other Java/Database Integration Solutions
How to Obtain and Install
Supported Databases
Chapter 2. Getting Oriented
Application Architecture
Mapping Files
Generating Java Source
Application Configuration
Web Application
JSP Interface
Chapter 3. Starting from Java
Java Object Model
Generated Mapping Files
Generated Schema
Working with Artifacts and Owners
Chapter 4. Starting from an Existing Schema
Initial Schema
Using Middlegen
Generated Mapping Files
Generated Java
Working with the Database
Chapter 5. Mapping Files
Basic Structure
Mapping File Reference
Chapter 6. Persistent Objects
Sessions
Objects and Identity
Life-Cycle Methods
Chapter 7. Relationships
Database Relationships
Java Collection Relationships
Java Class Relationships
Any-Based Relationships
Bi-directional Relationships
Chapter 8. Queries
HQL
HQL Reference
Select
From
Where
Group By
Having
Order By
Criteria Queries
Native SQL Queries
Chapter 9. Transactions
Introduction to Transactions
Optimistic and Pessimistic Locking
Chapter 10. Performance
Finding and Solving Problems
Queries
Inserts
Connection Pooling
Caching
Chapter 11. Schema Management
Updating an Existing Schema
Generating Update and Drop Scripts
Chapter 12. Best Practices, Style Guide, Tips and Tricks
Reducing Code with Inversion of Control
Reducing Session Creation Impact with ThreadLocal
Using Hibernate as an EJB BMP Solution
Integrating with Other Technologies
Applications That Use Hibernate
Strategies for Getting Started
Chapter 13. Future Directions
Hibernate 3.0
EJB 3.0
Here and Now
Index
SYMBOL
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X

What Is Hibernate?

As stated on the Hibernate Web site, the goal of Hibernate "is to relieve the developer from 95 percent of common data persistence related programming tasks." By combining ordinary Java classes with XML descriptors, Hibernate provides an object-oriented view of a relational database.

As shown in Figure 1.2, most Java applications access a relational database via JDBC (route 1, as indicated in the diagram). By using Hibernate, a developer is freed from writing custom JDBC integration code and can focus on writing the presentation and business logic of the application (route 2). This doesn't have to be an all-or-nothing proposition; you can use an existing JDBC application in conjunction with Hibernate, migrating access as you go along.

Figure 1.2. Weblog & Post Java Objects


Hibernate allows you to choose a development methodology that fits your needs. If you are starting a new project from scratch, you may wish to start with a mapping file, automatically generating both the schema and the Java classes (Chapter 2). Alternatively, you may wish to start from a relational database schema or directly from Java code (Chapters 3 and 4). Each system has pros and cons, as described in the chapter covering it.

There are several conceptual components to Hibernate that will be described in detail in this book. Java classes and XML files are used by Hibernate to bind Java objects to a particular relational database schema (Chapter 5). Straightforward Java-based operations are then used to create, update, query, and delete records (Chapter 6). More complex relationships, including Java collections, class hierarchies, and database one-to-many, many-to-one, and many-to-many relationships can be managed by Hibernate in a very natural manner (Chapter 7). Rich queries can be expressed in terms of both a simple object-oriented query language and a "Criteria" system (Chapter 8). Hibernate has robust support for complex transactions (Chapter 9).

SO MUCH TO LEARN!

When you first start working with Hibernate, it is easy to feel overwhelmed (especially if you haven't already been exposed to an object/relational framework). If you are just starting out, I strongly recommend that you begin by skimming through this text, paying particular attention to sections that outline concepts new to you. Then download the source for this book from my Web site at http://www.cascadetg.com/hibernate/ and work through the examples one by one.

This text assumes a baseline knowledge of Java application development, traditional relational database concepts, and SQL. Many developers (especially those who are largely self-taught) will discover that some of the basic concepts underlying Hibernate are unfamiliar. If you hit such a wall, check with either a recent Java application development text (JDK 1.4 or later) or a solid book on SQL and relational database theory.

I recommend starting with the mapping filebased example described in Chapter 2. Understanding the mapping file is usually the biggest challenge for developers new to Hibernate. By inspecting the Java source and database schema generated by Hibernate, you can quickly understand how Hibernate functions.