Course Description

This 5-day Java Enterprise EJB3 and JPA2 training course provides a thorough coverage of the EJB3 technology – presented in a clear and effective manner. It starts with the basic concepts and APIs of EJB and then continues on with complex topics such as message driven beans and transactions. New concepts such as the use of annotations and the use of Dependency Injection to initialize references are covered in depth. The course also includes thorough coverage of managing persistence using the Java Persistence API 2 (JPA2).

The Enterprise JavaBeans 3 specification is a deep overhaul of the EJB specification that improved the EJB architecture by reducing its complexity from the developer’s point of view. It leverages annotations (introduced in Java 5) and Object-Relational Mapping (ORM) technologies to eliminate the dependence on complex EJB APIs, allow POJO (Plain Old Java Object) based development, and provide an effective technology for creating distributed, transactional components, and for mapping relational data to an object schema. The EJB 3.1 release is part of the JEE 6 specification and adds additional refinements and capability.


One year of Java programming experience (or equivalent) is preferred. Knowledge of relational databases and JDBC is strongly recommended.  Attendance at our Java Programming Introduction  and Java Programming Intermediate training courses will provide a suitable preparation for this course.

Who is this course for?

For experienced Java software developers who want to use EJB3 and JPA2.

Further Training

After some further on-the-job programming experience with the JEE platform, students should consider attending our Java JBoss Server Administration  training course to gain an understanding and skills in the configuration and management of a JEE Application Server.

Course content

What is EJB?
EJB Goals
Types of Enterprise JavaBeans
Java Persistence API
EJB and Java EE (Enterprise Editions)
EJB in Java EE Architecture
SOA with Web Services and EJB
EJB 3.0 Overview
EJB 2.X Problems
EJB 3.0 Goals
EJB 3.1 Goals
Session Bean Usage
Persistent Entity Usage
MDB Usage
Session Beans
Session Bean Overview
What are Session Beans?
Stateless Session Beans (SLSB)
Stateful Session Beans (SFSB)
Session Bean can be Distributed
Defining a Session Bean
Stateless Session Bean Definition
Remote and Local Business Interfaces
A Brief Note on Annotations
How Annotations Work
Annotation Definition
Using Annotations
What Else is Needed
Packaging and Deployment
JEE Packaging
ejb-jar File
Deployment Descriptor (DD)
Deployment Descriptors in EJB 3
ejb-jar File Structure
Enterprise Archive (.ear File)
Application.xml File
Web Application Structure – JEE 6
Server Deployment
EJB Container
The EJB Container
Server Deployment
JNDI Overview
How do Remote Clients get EJB Access
JNDI – Java Naming and Directory Interface
EJB Container Binds a Reference into JNDI
Client Looks up Reference in JNDI
JNDI Tree Structure
JNDI API Overview
The Context Interface
The InitialContext Class
Specifying the InitialContext Properties
Using JNDI
EJB Client Remote Client
Client View of a Session Bean
EJB 3.1 – Portable JNDI Names
Client Invocation of a Session EJB
PortableRemoteObject and Casting
Running a Client
Additional EJB Capabilities
Dependency Injection
An EJB Referencing another EJB
Injection of CatalogMaintenance
What is Happening
Deployment Descriptors
More About Deployment Descriptors
The XML Deployment Descriptor
The EJB Environment
Issues with Obtaining Resources
Referencing Resources External to EAR
Reference & Deployment Descriptor
Resolving a JNDI Name
Simple Environment Entries
Declaring Simple Environment Entries
Setter Injection
Resource Manager Connection Factories
More on the Enterprise Bean Environment
The Environment is a Level of Indirection
Looking up Resources in the Environment
Looking up via EJBContext
Looking up via JNDI API
More on the @Stateless Annotation
More on the @EJB Annotation
More on the @Resource Annotation
Deployment Descriptor vs Annotation
Stateless Session Bean Lifecycle & Interceptors
Stateless Session Bean State Diagram
Lifecycle of SSB
Client Call of a Stateless SB Method
Business Method Interceptors
InvocationContext Interface Details
Interceptor Method Details
Interceptor Class
Using Interceptor Classes
Method Level Interceptors
Lifecycle Callback Interceptors
Lifecycle Interceptor in the Bean Class
Lifecycle Interceptor in a Separate Class
Asynchronous Methods, Singleton Session Beans
Singleton Session Bean
Singleton Initialization
Singleton Concurrency
Asynschronous Method Invocations Using Future
Stateful Session Beans
Stateful Session Bean (SFSB) Overview
Coding a Stateful Session Bean
Stateful Session Bean Removal
Stateful Session Bean Clients
Stateful Session Passivation/Activation
When to Use Stateful Session Beans
@PrePassivate and @PostActivate
Stateful Session Bean State Diagram
The Timer Service
Programmatic Timers
The javax.ejb.Timer Interface
The javax.ejb.TimerService Interface
How the Timer Works
Schedule Expression
Issues with Using the Timer Service
Message-Driven Beans
Overview of Messaging Systems
What is Messaging?
Loose Coupling
When is Messaging Used?
Two Messaging Models
Publish/Subscribe – Illustrated
More on Publish/Subscribe
Point-to-Point – Illustrated
More on Point-to-Point (P2P)
Message Delivery – Push versus Pull
Overview of JMS API
What is Java Message Service?
API Structure
JMS Interfaces
Administered Objects
Administered Objects and JNDI – Illustrated
Client Workflow
Synchronous Queue Consumer Client
Asynchronous Queue Consumer Client
JMS Message Types
Message Header Fields
Message-Driven Beans
J2EE Message Producers and Consumers
Message-Driven Bean (MDB) Overview
Goals of Message-Driven Beans
MDB Consumption of a Message
@MessageDriven Details
Activation Configuration Properties
Specifying a Destination for an MDB
Specifying a Destination Using a DD
Message-Driven Bean Lifecycle
Lifecycle Overview
MDB State Diagram
Interceptor Methods
Transactions and Security
Transaction Overview
Transaction Lifecycle
Transactions Clarify Systems
Transactional System Overview
Overview of a Transactional System
Transactional System Components
Transactional Object
EJB Transaction Support
Transactions in EJB
EJB Declarative Transaction Management
Transactional Scope
EJB Transaction Attributes
Specifying Transaction Attributes
Beans Have a Say in Transactions
Beans can be Notified of Transaction Status
Transaction Attributes – Some Choices
Explicit/Bean-Managed Transactions
Transaction Isolation Levels
Multi-Process TX and Two Phase Commit
Security in EJB
Security Requirements
JEE Security
JEE Security Overview
EJB Security Overview
Programmatic Security
Transport Level Security with SSL
Exception Handling & Best Practices
Overview of Exceptions
Exception Hierarchy
Application Exceptions in EJB
Defining Application Exceptions
Container Handling of Application Exception
Bean Throwing of Application Exception
Client Handling of Application Exceptions
System Exceptions Indicate Failure
Container Handling of System Exception
Client Handling of System Exceptions
EJB 3 Best Practices
When to Use EJB
Keep Business Interfaces Coarse Grained
Session Façade Structure
Use Container-Managed Transactions
Transaction Duration
Local and Remote Business Interface
Session Bean Tuning
Clustering Session Beans
Introduction to the Java Persistence API (JPA 2)
JPA Overview
The Issues with Persistence Layers
Object-Relational Mapping (ORM) Issues
Java Persistence API Overview
JPA Benefits
Java Persistence Environments
JPA Architecture – High Level View
JPA Architecture – Programming View
Mapping a Simple Class
Entity Classes
Entity Class Requirements
Javax.persistence.Entity Annotation
The Event Class
javax.persistence.Id and ID property
Field Access or Property Access
The EVENTS Table
Generated Id Property
Mapping Properties
Basic Mapping Types
Temporal (Date/Time) Mappings
Persisting to the Database
Entity Manager and Persistence Context
The Entity Manager & Persistence Context
The Persistence Unit
Classes included in a Persistence Unit
The EntityManager & Persistence Context
EntityManager Interface
Obtaining an Entity Manger
Injecting an EntityManager
Container-Managed Entity Manager
Retrieving Persistent Objects
Default Mappings
@Basic and @Column
Field and Property Access
Mapping Enums
Updates and Queries
Inserting and Updating
Persisting a New Entity
Synchronization To the Database
Updating a Persistent Instance
Removing an Instance
Detached Entities
Querying and Java Pesistence Query Language (JPQL)
Java Persistence Query Language
JPQL Basics – SELECT Statement
Querying and the Query Interface
Executing a Query
JPA 2 – Generic Query Enhancements
Other Query Methods
Where Clause
JPQL Operators and Expressions
Query Parameters
Using Query Parameters
Named Queries
Criteria API (JPA 2)
Path Expressions
WHERE Clauses
Typed Path Expressions
Combining Predicates (and/or)
Additional Criteria API Capabilities
The Persistence Lifecycle
JPA Entity States
Transient and Persistent State
Detached and Removed State
JPA Object States and Transitions
The Persistence Context
Synchronization to the Database
Flushing the Entity Manager
Versioning / Optimistic Locking
Using a Detached Instance
Locking Objects
Entity Relationships
Relationships Overview
Object Relationships
Characteristics of Relationships
Characteristics of Relationships
Mapping Relationships
Unidirectional Many-To-One Relationship
The Table Structure – Many-To-One
The Owning Side
Using the Relationship
Bidirectional One-To-Many Relationship
Mapping the One-To-Many Relationship
Managing the Bidirectional Relationship
More on the Inverse Side
Other Collection Types
Transitive Persistence
The Cascade Element
Bidirectional One-To-One Relationship
Orphan Removal (JPA 2)
Many-To-Many Relationship
Specifying the Join Table
Choosing Cascade Behavior
Lazy and Eager Loading
Queries Across Relationships
Mapping Inheritance
Entity Inheritance
Details of Entity Inheritance
Single-Table Strategy
Entity Definitions for Single-Table
Single Table: Pros and Cons
Joined (Table per Subclass)
Entity Definitions for Joined
Joined: Pros and Cons
Table per Concrete Class
Using Embedded Objects
Embeddable Class
Reusing Embeddable Classes
Overriding Embedded Class Attributes
Compound Primary Keys
Compound Key with Embedded Id Class
Using an Embedded Id Class
Compound Key with ID Class
Element Collections (JPA 2)
Modelling a Collection of String Elements
Using an Element Collection
Mapping Collections of Embeddables
Additional Java Persistence Capabilities
More on Querying
Projection Queries
Aggregate Queries
Bulk Update and Delete
Native SQL Queries
Extended Persistence Contexts
Stateful Session Beans with Entity State
Extended Persistence context
Issues with Extended Persistence Context
XML Mapping Files
A Simple Entity Class
JPA XML Mapping File
Java Persistence with Java SE
Using JPA with Java SE
Java SE APIs
Java Persistence Best Practices
Primary Key Considerations
Use Named Queries
Use Lazy/Eager Loading Appropriately
Be Aware of Transaction Semantics
Encapsulate JPA Code
Use Report Queries Where Applicable
Optimize Read-Only/Mostly Data Access
Paging Data
Consider Going Outside of Java Persistence
Know Your Provider Implementation
Resources (EJB3 and JPA)