First Technology Transfer

Standard and Advanced Technical Training, Consultancy and Mentoring

Course JAV107 - Java Data Persistence Based Applications Using Hibernate and JPA2

Duration: 4 Days

Intended Audience

This course is aimed at reasonably experienced Java programmers. Experience of J2EE would be helpful, but is not essential.


Hibernate is, probably, the most widely used object-relational mapping (ORM) library for Java. ORM is used to persist Java objects to relational databases, and Hibernate does this in a transparent but flexible way. As well as being used stand-alone, it is also often integrated with the Spring framework when writing enterprise applications.

The JPA2 architecture provides an interface for implementing data persistence and represents an important development in Java persistence programming. As well as covering classical data persistence programming using Hibernate this course, in addition, covers practical programming using the JPA2 interface. Important aspects of JPA2 covered by the course include

  • Working with the JPA EntityManager, queries and JPQL (Java Persistence Query Language), and, also, the Criteria API (JPA 2)
  • Understanding and making use of collections and associations
  • Mapping inheritance hierarchies using JPA
  • Using JPA entities from session beans and a gaining a basic understanding of how JPA can be used together with Spring

Course Outline

  • Introduction
    • Overview of Hibernate and Object-Relational Mapping
    • Obtaining and installing Hibernate
  • Mapping Beans
    • Mapping POJOs (Plain Old Java Objects) using XML
    • Mapping POJOs using annotations
    • Mapping properties to columns
    • Using Sessions
    • Configuring the SessionManager
  • Modelling Relationships
    • Setting up relationships
    • Using one-to-many relationships
    • Bidirectional relationships
    • Many-to-many relationships
    • Inheritance relationships
    • Mapping collections
  • Queries
    • Queries in Hibernate
    • Introduction to the Criteria API
    • Creating queries using Criteria
    • Processing query results
    • Introduction to HQL
    • Creating HQL queries
    • Named queries
  • Introduction to Java Persistence API (JPA)
    • Overview of JPA
    • Mapping with JPA
    • Persistence Unit and EntityManager
    • Using (provider based) Logging Options
  • Updates and Queries
    • Inserting and Updating - Persisting new Entities, Updating an Instance, Removing an Instance
    • Querying and JPQL
    • Embedded Objects
    • Compound Primary Keys - @EmbeddedID, @IDClass, Defining Compound Keys
  • The Persistence Lifecycle
    • Transactions- an Overview and Transactions in JPA
    • The Persistence Lifecycle
    • Versioning and Optimistic Locking
    • Lifecycle Callbacks
  • Enitity Relationships
    • Relationships Overview: Object Relationships, Participants, Roles, Directionality, Cardinality
    • Relationship Mapping
    • Entity Inheritance Mapping
  • Element Collections (JPA 2)
    • Overview, Collections of Value Objects, @ElementCollection, @CollectionTable
    • Using Element Collections
    • Collections of Embeddables
  • Criteria API (JPA 2)
    • Overview of the Criteria API
    • Path Expressions, Building Queries (CriteriaBuilder, CriteriaQuery, Subquery, Predicate, Expression, Order, Selection, Join)
    • Executing Queries and Accessing Results
  • More Advanced JPA
    • XML Mapping Files
    • Bean Validation (JPA 2)
  • Integration aspects of JPA 2
    • Data Access Objects (DAO) and Java SE Integration
    • Integration with EJB
    • Using JPA with Java Web Apps
    • Integration with Spring