Course #:WA2215

Java Persistence (JPA) Programming using Rational Application Developer 8.0 Training

This 3 day training course teaches students about the standard persistence architecture provided by JPA. This standard can be used to replace third party persistence frameworks like Hibernate. By learning the programming model made available by the JPA standard and how to use it in various types of applications, developers can create applications that are more portable between environments and rely less on integration of third party libraries. Students will develop JPA applications using RAD 8.0 for the WebSphere Application Server 8.0 platform.


  • Java Persistence (JPA) specification
  • JPA Tools in Rational Application Developer 8.0
  • JPA queries
  • JPA relationships and inheritance
  • JPA-related design patterns
  • Using Rational Application Developer 8.0 tools to develop JPA applications

What you will learn

  After completing this course, the student should be able to:
  • Develop Java applications that use JPA to map persistent objects to the database
  • Control the mapping of the Java object model to the relational database schema
  • Query data using JPA queries (including JPA 2.0 Criteria queries)
  • Define complex mappings including relationships and inheritance
  • Utilize JPA in a variety of application types, including web, EJB, and standard Java applications
  • Be productive developers in the Rational Application Developer (RAD) environment
  • Deploy application code inside WebSphere Application Server 8.0


  This course is designed for Java programmers and web application designers who have interest in learning how to persist data from Java applications to relational databases using the Java Persistence API (JPA) using IBM's Rational and WebSphere tools.


  Intermediate level Java programming knowledge.
Course WA2099 Introduction to Java using Rational Application Developer 8.0 satisfies this requirement


  Three days

Outline of Java Persistence (JPA) Programming using Rational Application Developer 8.0 Training

Chapter 1. Overview of Enterprise JavaBeans (EJB)

  • What are EJBs?
  • Distributed Transaction
  • Distributed Security
  • Distributed Computing
  • Main Characteristics of EJBs
  • EJB Container
  • EJB Client
  • Annotations
  • Enterprise JavaBeans
  • Session Beans
  • Message-Driven Beans (MDBs)
  • Asynchronous Session EJBs
  • EJB Timers
  • EJB Lite
  • EJB Packaging
  • EJBs are Simple!
  • Summary

Chapter 2. Overview of Java Persistence API

  • Data Persistence
  • Java Persistence API
  • Entities
  • Session EJB vs JPA Entities
  • Entities
  • Persisting and Retrieving Data
  • Accessing Entities
  • EntityManager & Persistence Unit
  • Persistence Context
  • Entities - Example
  • persistence.xml – Hibernate Provider
  • persistence.xml – Open JPA Provider
  • persistence.xml - Toplink
  • Entity Instance Lifecycle
  • Creating EntityManager in Session EJB
  • Creating EntityManager in a Plain Java Class
  • Working With the EntityManager Interface
  • Transaction Basics
  • Summary
  • Creating Entities
  • JPA Project
  • Creating An Entity
  • Generated Entity Class
  • Code the Entity
  • JPA Tooling
  • Dependencies

Chapter 3. JPA Entity Lifecycle

  • Entity Lifecycle
  • When is an Entity Managed or Detached?
  • Implementing the CRUD Pattern
  • Accessing Entities Using Stateless Session Beans
  • Inserting Data
  • Retrieving Data
  • Updating Data
  • Deleting Data
  • Merging Entities
  • Merging Entities (example)
  • Life-Cycle Callbacks
  • Example: Internal callback
  • External Callback Class
  • Listener Class - Example
  • Synchronizing with Databases
  • Entity Lookup
  • JPAQL (JPA Query Language)
  • Summary

Chapter 4. Java Persistence Query Language (JPA QL)

  • JPA Query Language
  • Basic JPAQL Syntax
  • Simple SELECT Examples
  • Example of Using JPAQL
  • The SELECT clause
  • Reading Data from Code
  • The WHERE Clause
  • Example Using JPAQL from Session EJB
  • Named Query
  • Multiple Named Queries
  • TypedQuery
  • Bulk Updates
  • Bulk Delete
  • Running Native SQL Query
  • Native SELECT Query
  • Native SQL Delete and Insert
  • Named Native Query
  • Summary

Chapter 5. Basic JPA Entity Relationships

  • Relationship Between Entities
  • Anatomy of a Relationship
  • Foreign Key
  • Example Schema
  • One-to-One Unidirectional
  • Creating Entity Instances
  • Traversing the Relationship
  • The Cascade Behavior
  • One-to-One Bidirectional
  • Maintaining Bidirectional Links
  • Simplifying Bidirectional Links
  • Traversing the Relationship
  • Summary

Chapter 6. Complex Entity Relationships

  • One-To-Many and Many-To-One
  • Many-to-One Unidirectional
  • Creating Entity Instances
  • Traversing the Relationship
  • Modeling One-to-Many
  • Maintaining Bidirectional Links
  • Creating Entity Instances
  • Traversing the Relationship
  • Many-to-Many
  • Modeling Many-to-Many
  • Maintaining Bidirectional Links
  • Creating Entity Instances
  • Traversing Relationship
  • Modeling Unidirectional One-to-Many - @JoinTable
  • Modeling Unidirectional One-to-Many - @JoinColumn
  • Creating Entity Instances
  • Traversing the Relationship
  • Relationship in JPA QL
  • Fetching Optimizations
  • Lazy vs. Eager Initialization
  • Lazy Initialization
  • Various Problems with Lazy Initialization
  • Fetch Join Query
  • Summary

Chapter 7. JPA Entity Inheritance

  • Inheritance
  • Inheritance Example
  • Inheritance and Entities
  • Inheritance Strategies
  • Strategy 1: Single Table Per Class Hierarchy
  • Single Table Per Class Hierarchy
  • Table Structure: Single Table Per Class Hierarchy
  • Pros and Cons
  • Strategy 2: Table Per Concrete Class
  • Table Per Concrete Class
  • Table Per Concrete Class: JBoss Warning
  • Table Per Concrete Class
  • Table Structure: Table Per Concrete Class
  • Table Per Concrete Class: Pros and Cons
  • Strategy 3: Joined Subclasses
  • Joined Subclasses
  • Table Structure: Joined Subclasses
  • Joined Subclasses: Pros and Cons
  • Which Approach To Use?
  • Summary

Chapter 8. JPA Criteria Queries

  • JPA QL Limitations
  • Dynamic Queries with JPA Criteria API
  • Simple Criteria Query Example
  • The javax.persistence.criteria.CriteriaQuery Interface
  • The javax.persistence.criteria.CriteriaBuilder Interface
  • More Complex Example
  • Compounding Where Clause Predicates
  • Summary

Chapter 9. Transactions in EJB

  • Need for Transactions
  • Transactions
  • ACID Properties
  • Transaction Components
  • Distributed Transactions
  • Distributed Transaction Components - Two Phase Commit
  • Java Transaction API (JTA)
  • EJB Transaction Basics
  • Transaction Propagation
  • Transaction Outcome
  • Container-Managed Transaction
  • Transaction Attributes
  • Container-Managed Transaction Settings
  • Interacting with Container-Managed Transactions
  • Container-Managed Transaction – Example
  • Application Exceptions in Container-Managed Transactions
  • Transaction Attributes Support
  • Bean-Managed Transaction Management Type
  • Summary

Chapter 10. JPA Design Patterns

  • Data Transfer Object (DTO) Pattern
  • JPA Entity as DTO
  • Problem With JPA Entity as DTO
  • Version Number pattern
  • JPA and Version Number Pattern
  • Primary Key Generation
  • JPA and Primary Key Generation
  • Fast Lane Pattern
  • JPA and Fast Lane Pattern
  • Summary
We regularly offer classes in these and other cities. Atlanta, Austin, Baltimore, Calgary, Chicago, Cleveland, Dallas, Denver, Detroit, Houston, Jacksonville, Miami, Montreal, New York City, Orlando, Ottawa, Philadelphia, Phoenix, Pittsburgh, Seattle, Toronto, Vancouver, Washington DC.