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 3. Starting from Java

Combining Hibernate with XDoclet makes it possible to start from Java code when building an application. Using XDoclet markup tags (similar to the tags used by javadoc), you can generate the *.hbm.xml files required by Hibernate directly from your Java source files.

XDoclet, available from http://xdoclet.sourceforge.net/, is an open-source framework for annotating Java source files with special comments, which are then used to construct configuration files used by a variety of different environments.

Many developers first encounter XDoclet when working with EJB 2.X as a tool to help manage the complexity of EJB 2.X development. XDoclet-style annotations have become so popular that support for similar annotations (as described by JSR 175, http://jcp.org/en/jsr/detail?id=175) is included as a standard extension in the upcoming release of Java (Java 2 Platform, Standard Edition 5.0). The early draft specification for EJB 3.0 uses annotations in lieu of XML descriptors. The upshot is that the use of XDoclet and Hibernate is (as of this writing) a close approximation of the development model being suggested for EJB 3.0.

WARNING

There are three significant downsides to using annotations as your development solution. The first is the addition of (yet another) complex tool to your build process. The second is the relative difficulty of debugging and otherwise tracing the source of problems with the generated mapping file. The third downside of annotations is that configuration information is now stored directly in your Java source files. Given all of these downsides, I have found annotations to be much more error-prone and difficult to work with than simply starting from a mapping file, as described in Chapter 2.


In constructing the application in this chapter, we will start from a set of Java sources and then walk through the rest of the development path.