Harnessing Hibernate

Book description

Harnessing Hibernate is an ideal introduction to the popular framework that lets Java developers work with information from a relational database easily and efficiently. Databases are a very different world than Java objects, and they often involve people with different skills and specializations. With Hibernate, bridging these two worlds is significantly easier, and with this book, you can get up to speed with Hibernate quickly.

Rather than present you with another reference, Harnessing Hibernate lets you explore the system, from download and configuration through a series of projects that demonstrate how to accomplish a variety of practical goals. The new edition of this concise guide walks you through Hibernate's primary features, which include mapping from Java classes to database tables, and from Java data types to SQL data types. You will also learn about Hibernate's data query and retrieval facilities, and much more.

By reading and following along with the examples, you can get your own Hibernate environment set up quickly and start using it for real-world tasks right away. Harnessing Hibernate teaches you how to:

  • Perform Object/Relational mapping
  • Work with persistent data from Java code
  • Work with groups and relationships between objects
  • Extend Hibernate's rich type support for your own needs
  • Simplify query creation using criteria and examples
  • Use the Hibernate Query Language (HQL) and understand how it differs from SQL
  • Use Hibernate in conjunction with Spring
  • Use Hibernate in conjunction with other packages, such as the Stripes web framework and the Eclipse IDE

Once you're past the first few chapters, you can jump to topics that you find particularly interesting or relevant. All background material and explanations of how Hibernate works and why is in the service of a focused task. Source code can be downloaded from the book's website.

If using SQL is an uncomfortable chore, Harnessing Hibernate offers you an effective and trouble-free method for working with the information you store in your applications.

Publisher resources

View/Submit Errata

Table of contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. How to Use This Book
    2. Font Conventions
    3. On the Web Site
    4. How to Contact Us
    5. Acknowledgments
      1. James Elliott
      2. Ryan Fowler
      3. Timothy O’Brien
  3. I. Hibernate in a Hurry
    1. 1. Installation and Setup
      1. Getting an Ant Distribution
        1. Why do I care?
        2. How do I do that?
      2. Check Your Java Version
        1. What just happened?
        2. What about…
      3. Getting the Maven Tasks for Ant
        1. How do I do that?
      4. Installing the Maven Tasks for Ant
      5. Using the HSQLDB Database Engine
        1. Why do I care?
        2. How do I do that?
        3. What about…
      6. Using Hibernate Core
        1. How do I do that?
      7. Setting Up a Project Hierarchy
        1. Why do I care?
        2. How do I do that?
        3. A quick test
        4. What just happened?
        5. What’s next?
        6. Why didn’t it work?
    2. 2. Introduction to Mapping
      1. Writing a Mapping Document
        1. Why do I care?
        2. How do I do that?
      2. Generating Some Class
        1. How do I do that?
      3. Cooking Up a Schema
        1. How do I do that?
        2. What just happened?
        3. What about…
    3. 3. Harnessing Hibernate
      1. Configuring Hibernate
      2. Creating Persistent Objects
        1. How do I do that?
        2. What just happened?
        3. What about…
      3. Finding Persistent Objects
        1. How do I do that?
        2. What just happened?
        3. What about…
      4. Better Ways to Build Queries
        1. Why do I care?
        2. How do I do that?
        3. What about…
    4. 4. Collections and Associations
      1. Mapping Collections
        1. How do I do that?
        2. Why didn’t it work?
        3. What about…
        4. What just happened?
      2. Persisting Collections
        1. How do I do that?
        2. What just happened?
      3. Retrieving Collections
      4. Using Bidirectional Associations
      5. Working with Simpler Collections
        1. How do I do that?
    5. 5. Richer Associations
      1. Eager and Lazy Associations
        1. How do I do that?
        2. What about…
        3. My head hurts
      2. Ordered Collections
        1. How do I do that?
      3. Augmenting Associations in Collections
        1. How do I do that?
        2. What just happened?
        3. What about…
      4. Lifecycle Associations
        1. How do I do that?
      5. Reflexive Associations
        1. How do I do that?
    6. 6. Custom Value Types
      1. Defining a User Type
        1. How do I do that?
      2. Defining a Persistent Enumerated Type
      3. Using a Custom Type Mapping
        1. How do I do that?
        2. What about…
      4. Working with Persistent Enumerations
        1. How do I do that?
        2. Not so fast!
        3. What just happened?
        4. Why didn’t it work?
      5. Building a Composite User Type
        1. How do I do that?
        2. What about…
    7. 7. The Annotations Alternative
      1. Hibernate Annotations
        1. Why do I care?
        2. How do I do that?
        3. Why do I have to?
      2. Annotating Model Objects
        1. How do I do that?
        2. Annotating Track
        3. Annotating Album
        4. Does it work?
      3. An Alternate Approach
        1. What now?
    8. 8. Criteria Queries
      1. Using Simple Criteria
        1. How do I do that?
        2. What about…
      2. Compounding Criteria
      3. Projection and Aggregation with Criteria
        1. How do I do that?
      4. Applying Criteria to Associations
        1. How do I do that?
        2. What just happened?
      5. Querying by Example
        1. How do I do that?
      6. Property-Oriented Criteria Factories
        1. What about…
    9. 9. A Look at HQL
      1. Writing HQL Queries
        1. How do I do that?
        2. What just happened?
        3. What about…
      2. Selecting Properties and Pieces
        1. How do I do that?
        2. What about…
      3. Sorting
        1. How do I do that?
      4. Working with Aggregate Values
        1. How do I do that?
        2. What just happened?
      5. Writing Native SQL Queries
        1. How do I do that?
        2. What about…
  4. II. Playing Nice with Others
    1. 10. Connecting Hibernate to MySQL
      1. Setting Up a MySQL Database
        1. How do I do that?
      2. Connecting to MySQL
      3. Trying It Out
        1. What just happened?
      4. Looking at the Data
        1. What about…
    2. 11. Hibernate and Eclipse: Really Using the Hibernate Tools
      1. Installing the Hibernate Tools in Eclipse
        1. How do I do that?
        2. What went wrong?
        3. Now what?
      2. Creating a Hibernate Console Configuration
      3. More Editing Support
        1. But wait, there’s more!
      4. The Hibernate Console Perspective
        1. What about…
      5. Code Generation
      6. Mapping Diagrams
    3. 12. Maven in More Depth
      1. What Is Maven?
        1. Maven’s standard directory layout
      2. Installing Maven
      3. Building, Testing, and Running a Project
      4. Generating IDE Project Files using Maven
      5. Generating Reports with Maven
      6. A Maven Project Object Model
        1. Parent/child Project Object Models
      7. The Maven Build Lifecycle
      8. Using the Maven Hibernate3 Plug-in
        1. Configuring the Hibernate3 plug-in
        2. Generating Hibernate mapping documentation
      9. Becoming a Maven Maven
    4. 13. Put a Spring in your Step: Hibernate with Spring
      1. What Is Spring?
        1. What is inversion of control?
        2. Combining Spring and Hibernate
        3. Adding the Spring framework as a project dependency
      2. Writing a Data Access Object
        1. What is a Data Access Object?
        2. Why would I want to use a DAO?
        3. Writing the ArtistDAO interface
        4. Implementing the ArtistDAO interface
        5. What HibernateDaoSupport provides
        6. How do I do that?
        7. Where are the other DAOs?
      3. Creating an Application Context
        1. Hibernate configuration properties
      4. Putting It All Together
        1. Transactions: the test interface
        2. How do I activate the transactional annotation?
        3. Adapting CreateTest, QueryTest, and AlbumTest
        4. TestRunner: loading a Spring ApplicationContext
        5. Running CreateTest, QueryTest, and AlbumTest
        6. It worked! Now what?
    5. 14. The Finishing Touch: Stripes with Spring and Hibernate
      1. Earn Your Stripes
        1. DispatcherServlet
        2. StripesFilter
        3. ActionBeans
        4. Views
      2. Prepare Tomcat
      3. Create the Web Application
        1. What just happened?
      4. Add Stripes
        1. Write up an ActionBean
        2. What just happened?
        3. What’s next?
      5. Dealing with Associations
        1. Interceptors: a powerful way to extend stripes
  5. A. Hibernate Types
    1. Basic Types
    2. Custom Value Types
    3. “Any” Type Mappings
    4. All Types
  6. B. The Criteria API
    1. The Criterion Factory
    2. The Projection Factory
    3. The Order Factory
    4. The Property Factory
  7. C. Hibernate SQL Dialects
    1. Getting Fluent in the Local SQL
  8. D. Spring Transaction Support
    1. Using the Spring Framework’s Transactional Annotation
      1. Transactional annotation attributes
      2. Transaction propagation
      3. Transaction isolation
    2. Using a JTA Transaction Manager
  9. E. Where to Go Next
    1. Online Manuals
    2. Books
    3. Source Code
    4. Dealing with Newer Releases
    5. Getting Involved
  10. Index
  11. About the Authors
  12. Colophon
  13. Copyright

Product information

  • Title: Harnessing Hibernate
  • Author(s): James Elliott, Timothy M. O'Brien, Ryan Fowler
  • Release date: April 2008
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596517724