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

Chapter 7. Relationships

Object/relational mapping highlights the confusion arising from the fact that experts in the object-oriented world and the relational world use different concepts and terminology. For example, a Java developer may speak in terms of a collection and classes, whereas a database guru will talk of things in terms of foreign keys and joins. In this chapter, we'll try to explain and reconcile these terms.

The discussion in this chapter breaks the different types of relationships into a few basic categories.

  • Database Relationships: How relationships are viewed from a database perspective. Regardless of the type of relationship you choose, it will (obviously) be stored in the database somehow.

  • Java Collection Relationships: How groups of objects can relate to one other. Governs the precise behavior of a database relationship from the Java application's perspective. All collection tags (described in Chapter 5) require a nested database relationship tag.

  • Java Class Relationships: The expression of a Java class hierarchy in a database. An example of this is shown in Chapter 3.

The chapter concludes with a discussion of bi-directional collection relationships and the notion of an "any" relationship, one of the more advanced uses of Hibernate that combines aspects of Java class relationships with collection behavior.

TIP

Hibernate uses many terms in ways that differ from what a Java developer might expect. For example, the Java terms component, class, association, subclass, and collection also refer to specific Hibernate functionality or mapping tags. If a reference to a concept is confusing, make sure that you understand whether the context is a database, Java, or Hibernate.