877-277-2477
info@capstonecourseware.com
118. Java Persistence with Hibernate
Version 3.2.1

Book cover

This course develops skills in using the Object/Relational Mapping tool Hibernate®. The course uses the latest release version of Hibernate, 3.2, which is directly related to the new EJB 3.0 version defined in Java EE 5.0.

By the end of the course, students will be prepared to set-up and use Hibernate as the persistence mechanism in Java applications.

A bridge module is also available that illustrates how the Spring framework's persistence module compliments Hibernate; this brief presentation can easily be added to the end of the class and works especially well to cap off a week of training using this course and one of our Spring courses.

Prerequisites

  • Intermediate knowledge of Java programming; Course 103 is excellent preparation
  • Some familiarity with SQL, relational databases, and the Java Database Connectivity (JDBC) interfaces will be helpful; Course 168 is an optional precursor to this course

Learning Objectives

  • Configure Hibernate using both properties files and XML documents.
  • Create mapping documents for Java classes.
  • Define object relationships and build mapping documents to model them.
  • Use components to model composition relationships in the object model.
  • Work with one-to-one, many-to-one, and many-to-many relationships.
  • Evaluate the different approaches to modeling inheritance and polymorphism in database schema.
  • Build Java applications that use Hibernate to create, retrieve, update, and delete objects.
  • Use Hibernate's Criteria Query API to do searches and Query By Example.
  • Work with Hibernate Query Language (HQL) to generate object-based SQL.
  • Understand Hibernate sessions and transactions and their impact on performance.

Timeline: 2 days.

IDE Support: Eclipse 3.2

  • In addition to the primary lab files, an optional overlay is available that adds support for Eclipse 3.2. Students can code, build, and test all exercises from within the IDE; a handful of database-administration tasks must be performed from a command console. See also our orientation to Using Capstone's Eclipse Overlays, and please be advised that this is an optional feature; it is not a separate version of the course, and the course itself does not contain explicit Eclipse-specific lab instructions.

Chapter 1. Introduction to Hibernate

  • The Object/Relational Mapping Problem
  • JDBC
  • The Hibernate Alternative
  • Hibernate Architecture and API

Chapter 2. Configuring Hibernate

  • The Hibernate Distribution
  • Required Libraries
  • Configuration Files
  • hibernate.properties
  • hibernate.cfg.xml
  • Programmatic Configuration

Chapter 3. Hibernate Persistence

  • The SessionFactory Interface
  • Object States
  • The Session Interface
  • Transactions
  • Session Duration
  • The Data Access Object Pattern

Chapter 4. Object/Relational Mapping

  • O/R Mapping Issues
  • The Mapping Vocabulary
  • Primary Keys and Identity
  • ID Generators
  • Mapping Associations
  • Unidirectional and Bidirectional Associations
  • Managing Cardinality
  • Strategies for Mapping Inheritance

Chapter 5. The Criteria Query API

  • Criteria Queries
  • The Criteria Interface
  • Using Restrictions
  • Windowing Results
  • Sorting
  • Traversing Associations
  • Projections and Aggregates
  • Grouping
  • Query By Example (QBE)

Chapter 6. Hibernate Query Language

  • Building HQL Queries
  • The Select Clause
  • The Where Clause
  • Named and Entity Parameters
  • Associations and Aggregates
  • Bulk Updates and Deletes
  • Named Queries
  • Using Native SQL

Appendix A. Learning Resources

System Requirements

Hardware Requirements (Minimum) 500 MHz, 256 meg RAM, 500 meg disk space.
Hardware Requirements (Recommended) 1.5 GHz, 512 meg RAM, 1 gig disk space.
Operating System Tested on Windows XP Professional. Course software should be viable on all systems which support a J2SE 5.0 JDK.
Network and Security Limited privileges required -- please see our standard security requirements.
Software Requirements All free downloadable tools.
Hibernate® is a registered trademark of Red Hat, Inc. Neither the author nor the publisher of this course is affiliated with Red Hat, Inc. This product is not endorsed by Red Hat, Inc. in any way.