Table of Contents
preface xv
acknowledgments xvii
about this book xviii
about the cover illustration xxiv
- 1 Why Hibernate?
- Understanding object persistence
- Identity - Inheritance - Associations - Object/relational mapping
- Using direct JDBC
- Example application - Retrieving object graphs using JDBC - Persisting object graphs to a relational model - Deleting object graphs - Querying object graphs
- Persistence with Hibernate
- Simplicity and flexibility - Completeness - Performance
- Summary
- 2 Installing and building projects with Ant
- Getting a Hibernate distribution
- Installing Ant - Getting Ant - Extracting and installing Ant
- Setting up a database
- Getting MySQL - Testing MySQL - MySQL drivers
- Setting up a project
- Defining directories - Ant 101 - Running Ant
- Habits of highly effective build files
- Connecting Hibernate - Reusable build files - Expanding your horizons
- Summary
- 3 Hibernate basics
- Configuring Hibernate
- Basic configuration
- Creating mapping definitions
- IDs and generators - Properties - Many-to-one element - Proxies - Collections - Cascades - Fetching associated objects
- Building the SessionFactory
- Configuring the SessionFactory
- Persisting objects
- Retrieving objects
- The Session cache
- Advanced configuration
- Connection pools - Transactions - Cache providers
- Inheritance
- Table per class hierarchy - Table per subclass
- Summary
- 4 Associations and components
- Associations
- Many-to-one relationships, in depth - The central configuration file - Defining sample data
- Building tables with Ant and SchemaExport
- Logging with log4j and Commons Logging - Running SchemaExport - Loading the Events - Refactoring - Finding Events - Cascades
- Components
- What's in a component? - Mapping a component - Why use a component?
- Summary
- 5 Collections and custom types
- Persisting collections and arrays
- Using interfaces - Mapping persistent collections - Collection types - Lazy collections - Sorted collections - Bidirectional associations - Cascading collections
- Implementing custom types
- UserTypes - Implementing CompositeUserTypes
- Summary
- 6 Querying persistent objects
- Using HQL
- session.find(?) - The Query interface - Outer joins and HQL - Show SQL
- Query substitutions - Query parser
- Querying objects with HQL
- The FROM clause - Joins - Selects - Using functions - HQL properties - Using expressions
- Criteria queries
- Stored procedures
- Hibern8IDE
- Summary
- 7 Organizing with Spring and data access objects
- The ubiquitous DAO pattern
- Keeping the HQL together
- Analyzing the DAO
- Boilerplate code - Potential duplication - Detached objects only
- The Layer Supertype pattern
- Creating an AbstractDao
- The Spring Framework
- What's in a template? - Beans and their factories
- Summary
- 8 Web frameworks: WebWork, Struts, and Tapestry
- Defining the application
- A quick overview of MVC
- Service Layer pattern
- Decoupling Hibernate from the web layer
- Working with detached objects - Session scope - Accessing the Session from the Controller - Accessing the Session from the Service layer
- WebWork
- WebWork fundamentals - Creating controllers
- Struts
- Struts fundamentals - Building Struts Actions
- Tapestry
- Getting started - Tapestry fundamentals - HTML views - Page controller - Page specification - web.xml
- Hibernate in the view layer
- Summary
- 9 Hibernating with XDoclet
- Essential XDoclet
- JavaDoc basics - XDoclet: Building your own tags - Installing XDoclet - Configuring Ant
- Making single objects persistent
- The @hibernate.class tag - The @hibernate.id tag - The @hibernate.property tag - The @hibernate.column tag
- Basic relationships
- The @hibernate.many-to-one tag - The @hibernate.component tag
- Building collections
- One-to-many: a kicking set of Speakers - The @hibernate.set tag - The @hibernate.collection-key - The @hibernate.collection-one-to-many tag
- Going where no XDoclet has gone before
- Merge points - Property substitution
- Generating the hibernate.cfg.xml file
- Summary
- 10 Unit testing with JUnit and DBUnit
- Introduction to unit testing
- Automate those tests - Assertions - Expect failures
- JUnit
- Test-infecting your build file - Polishing off the build file
- Testing the persistence layer
- What do we want to test? - Testing basic persistence - Testing queries - General database testing tips 331
- Testing with DBUnit
- Loading test data - ProjectDatabaseTestCase
- Summary
- 11 What's new in Hibernate 3
- Filters
- Mapping improvements
- Multiple table mapping - Discriminator formulas - Union subclasses - Property references
- Dynamic classes
- Annotations
- Stored procedures and SQL
- Persistence events
- Lazy properties
- Summary
Appendix: The complete Hibernate mapping catalog
Index