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

Why Object/Relational Mapping?

Let's take a look at what the difference between an object and a relational model means. First, an example of object inheritance, as shown in Figure 1.1.

Figure 1.1. Simple Object Hierarchy


Consider the data associated with these objects. For example, you may wish to store the fang length for the mammals, and the number of fins on the fish, but you're also keeping track of the height and weight that you would track for all animals. Expressing this hierarchical relationship in an object-oriented programming language is easy, convenient, and efficient.

Relational databases, in comparison, view data in terms of tables. Structured Query Language (SQL) is the standard mechanism for interaction with a relational database. Most critically, data is viewed in terms of tables, columns, and rows. Relational capabilities allow multiple tables to be integrated and perform sophisticated data retrieval, allowing powerful mining and reporting capabilities.

Unfortunately, it is surprisingly difficult to map the tables and queries one might express in SQL to the hierarchical, object-oriented capabilities of a modern programming language. To store the data associated with an object hierarchy, as shown in Figure 1.1, in a database could require as many as seven tables, with many complex SQL statements required to perform the retrieval of all of the data associated with a single halibutor a single table with many unused fields, depending on the record entry. Hibernate allows you to easily use any of these potential database structures seamlessly and naturally from Java.