table of contents

Hibernate & JPA Tutorial:
Flexible Persistence for Java EE Applications

Interested in training from the author of these tutorials? See the upcoming Spring & Hibernate/JPA courses in Maryland, or contact hall@coreservlets.com for info on customized courses at your location.


This tutorial was written by Matt Cherry and is derived from the world-renowned coreservlets.com Java EE training courses. It is intended as a fast introduction to Hibernate and JPA for people that are already familiar with Java programming. For learning basic Java, please see these tutorials. The Hibernate and JPA training course on which this tutorial is based is usually taught on-site at customer locations, but various Java EE training courses at public venues are periodically scheduled for people with too few developers for an onsite course. For descriptions of the various other courses that are available, please see the J2EE training course page. To inquire about a customized training course at your location, please contact Marty at hall@coreservlets.com.

If you find these free tutorials helpful, we would appreciate it if you would link to us.

Source Code

Source code for all examples in this tutorial can be downloaded from the Hibernate sample code repository.

PowerPoint Files for University Faculty

The PDF files in this tutorial contain the complete text of the original PowerPoint files, so if your goal is learning Hibernate, just stick with this tutorial. However, as a service to instructors teaching full-semester courses at accredited universities, coreservlets.com will release the original PowerPoint files for free. Please see the instructor materials page for details.

An Introduction to Hibernate

Tutorial section:

Topics:

  • Refresher in enterprise application architectures
  • Traditional persistence
  • Hibernate motivation
  • Installation

Source code:


Walk-through of a Simple Hibernate Example

Tutorial section:

Topics:

  • Defining the domain model
  • Setting up the Hibernate configuration file
  • Creating the domain object mapping files
  • Making Hibernate aware of the mapping files
  • Updating the hibernate.cfg.xml with list of mapping files
  • Implementing a HibernateUtil class
  • Writing the code

Source code:


Association and Collection Mapping

Tutorial section:

Topics:

  • Understand Collection and Association relationships
  • See how to realize relationships in Java and databases
  • Walk through the Hibernate approach of mapping both Collections and Associations

Source code:


Component and Inheritance Mapping

Tutorial section:

Topics:

  • The difference between Components and Entities
  • Some uses of Components, and their mapping
  • Strategies and implementations for realizing inheritance

Source code:


Object Lifecycle, Persistence, and Session Management

Tutorial section:

Topics:

  • Entity lifecyle
    • The lifecycle of Hibernate entities, when they transition from state–to–state, and how this affects development
  • Persistence details
    • A closer look at persistence
    • How Hibernate manages dirty and related objects
  • Hibernate sessions
    • How Hibernate uses a Session to track and optimize user activities

Source code:


Transaction Management and Automatic Versioning

Tutorial section:

Topics:

  • Transactions
    • Brush up on transactions, and recognize they're not just for databases
    • Explore the different ways to include transactions into applications
  • Protecting user data
    • Learn a technique for ensuring that persistent changes to objects don't inadvertently overwrite other user's actions

Source code:


Hibernate Querying

Tutorial section:

Topics:

  • Briefly review SQL querying
  • Discover Hibernate’s different approaches to querying a database
  • Get acquainted with the ‘Query by Criteria’ technique
  • Introduce the ‘Query by Example’ offshoot

Source code:


Hibernate Query Language and Native SQL

Tutorial section:

Topics:

  • The Hibernate Query Language
    • Introducing the Hibernate Query Language
    • Leveraging HQL to write database queries
  • Native SQL
    • Understanding when to write your own SQL
    • Executing Native SQL with Hibernate

Source code:


Advanced Hibernate Features

Tutorial section:

Topics:

  • Batch Processing
  • Data Filtering
  • Interceptors and Events
  • Calling Triggers and Stored Procedures
  • 2nd Level Cache
  • Statistics
  • DDL Generation
  • Integration with Spring

Source code:


The Java Persistence API (JPA)

Tutorial section:

Topics:

  • Become acquainted with the Java Persistence API (JPA)
  • Compare and contrast Hibernate and JPA
  • Learn how to setup and use Hibernate as a JPA provider

Source code:

More Information

Java

JSF (JavaServer Faces)

Servlets & JSP
Ajax, GWT, & JavaScript

Spring, Hibernate, & JPA

Struts