Skip to main content

Instructor-led training

Fast Track to the Java Persistence API Version 2 (JPA 2) Training in Romulus, Michigan

As part of the complete overhaul of the Enterprise JavaBeans (EJB) specification, database persistence was broken out into a completely separate specification, the Java Persistence API (JPA).

What you'll learn

As part of the complete overhaul of the Enterprise JavaBeans (EJB) specification, database persistence was broken out into a completely separate specification, the Java Persistence API (JPA). JPA replaces entity beans with powerful new Object-Relational Mapping (ORM) capabilities based on proven technologies such as Toplink and Hibernate. This course includes all important features from JPA 2, and is also suitable for users of the 1.0 release. JPA supports a POJO (Plain Old Java Object) based model using annotations which lets you develop persistent classes following common Java idioms. It supports entity relationships, inheritance, polymorphism, composition, and much more. The Java Persistence Query Language (JPQL), which is based on SQL but operates on the object model, provides a powerful bridge between the object and relational worlds. JPA also allows you to express queries using native SQL, including the capability to map the SQL query results to persistent entities This course covers everything you need to know to begin working with the Java Persistence API in a very short time. It covers all the important concepts necessary to access and update data stored in relational databases. It includes an extensive series of labs to exercise all major capabilities.

Private Training for Teams

This course is offered as private, instructor-led training for organizations, onsite in Romulus, Michigan or live online. Dates, delivery format, and course content are arranged around your team's requirements.

This course is not currently scheduled as a public class for individual enrollment.

Request Group Training

Prerequisites

One year of Java programming experience (or equivalent) is preferred.

Course Outline

Introduction to Java Persistence API (JPA)

Overview
Persistence Layers, Object-Relational Mapping (ORM), JDBC
JPA Overview
Mapping with JPA
Entities and @Entity, ids and @Id,
Generated Id Values
Basic Mapping Types
Persistence Unit and EntityManager
Persisting to the DB, the EntityManager API
Persistence Units, Config, Persistence Context
Retrieving Persistent Entities with find()
More About Mappings
Default Mappings, @Basic, @Column
Field vs. Property Access
Temporal (Date/Time) Mappings
Logging Options (Provider based)
 
Updates and Queries
Inserting and Updating - Persisting new Entities, Updating an Instance, Removing an Instance
Querying and JPQL
Entity Based Queries, SELECT ,WHERE
Query Interface, Executing Queries, Generic Queries (JPA 2)
JPQL Operators, Expressions, and Parameters
Named Queries
Additional Query Capabilities
Projection query, Ordering, Aggregate Query, Build Update and Delete
Embedded Objects
@Embeddable, @Embedded
Defining and using Embedded Objects
Compound Primary Keys - @EmbeddedID, @IDClass, Defining Compound Keys
 
The Persistence Lifecycle
Transaction Overview and Transactions in JPA
Transaction Overview
EntityTransaction API (including JTA and resource-local EntityManager)
The Persistence Lifecycle
JPA Entity States (New, Managed, Detached, Removed), and Entity State Diagram
Persistence Context - Lifespan, Propagation
Synchronization to the DB
Versioning and Optimistic Locking
Overview, Detached Instances
Versioning, @Version, Optimistic Locking
Lifecycle Callbacks
@PrePersist, @PostPersist, etc.
Entity Listeners, @EntityListeners
 
Entity Relationships
Relationships Overview: Object Relationships, Participants, Roles, Directionality, Cardinality
Relationship Mapping
Mapping Overview (1-1, 1-N, N-1, N-N)
Unidirectional and Bidirectional
@ManyToOne, @OneToMany, Table Structures
Relationship Inverse - Owning Side
Collection Types (List, Set, etc)
Cascading Over Relationships (including orphanRemoval - JPA 2)
@ManyToMany, @OneToOne
Lazy and Eager Loading
Queries Across Relationships (Inner Joins, Outer Joins, Fetch Joins)
Entity Inheritance Mapping
Overview
Single Table Mapping
Joined (Table per Subclass) Mapping
Table per Concrete Class Mapping
Pros and Cons
Element Collections (JPA 2)
Overview, Collections of Value Objects, @ElementCollection, @CollectionTable
Using Element Collections
Collections of Embeddables
 
The Crietria 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
 
Additional JPA Capabilities
XML Mapping Files
Bean Validation (JPA 2)
Best Practices
Primary Keys, Named Queries, Lazy/Eager Loading, Transactional Semantics, Encapsulation, Report Queries
 
Integration
Data Access Objects (DAO) and Java SE Integration (Optional)
DAO Overview
JpaUtil Class for EntityManager management in Java SE
Lifecycle Considerations
Integration with EJB (Optional)
Using JPA with Session Beans
Container Managed (Injected) Entity Manger
JTA Transactions and Lifecycle Considerations
Extended Persistence Contexts
Using JPA with Java Web Apps
Using EntityManager in Web apps - request scoping
Lazy Loading - Open EntityManager in View Pattern
Integration with Spring (Optional)
Injection of EntityManger, EntityManagerFactory
LocalEntityManagerFactoryBean
JPA/Spring Based DAO

What makes JPA hard to master

The annotations are quick to learn. The difficulty is that JPA hides a stateful system behind them. An entity is not just an object: it is New, Managed, Detached or Removed, and the persistence context decides when changes reach the database. The syllabus builds this up in order.

  • Mapping basics first. @Entity, @Id, generated ids, @Basic and @Column, field versus property access, and temporal mappings. Then the EntityManager API, persistence units and find().
  • Queries next. JPQL, named queries, parameters, projection, aggregates and bulk update and delete. A common misconception is that JPQL is SQL against tables. It queries the object model, and the course separates it from native SQL with result mapping.
  • Lifecycle and concurrency. Transactions (including JTA versus resource-local), persistence context lifespan and propagation, synchronization, @Version with optimistic locking, and lifecycle callbacks. Behavior with detached instances is where many production bugs start.
  • Relationships. 1-1, 1-N, N-1 and N-N, unidirectional versus bidirectional, the owning side, cascading with orphanRemoval, lazy versus eager loading, and inner, outer and fetch joins. Most people find the owning side and fetch strategy the hardest part.
  • Structure and the Criteria API. Embeddables, compound keys, the three inheritance strategies with their trade-offs, element collections, and the JPA 2 Criteria API (CriteriaBuilder, CriteriaQuery, Predicate, Subquery).

Who it suits and what to take around it

This is an introductory, three-day course for Java developers who need to read and write persistence code against relational databases. One year of Java experience is preferred. Familiarity with SQL and JDBC helps, since the opening module places JPA relative to persistence layers, ORM and JDBC. The description says the content also suits users of the 1.0 release. Developers who need a stronger Java base first can start from the Java Programming courses and learning guide.

The integration modules (DAOs with Java SE, EJB session beans with container-managed entity managers, web applications, and Spring) are marked optional in the syllabus. If your target is container-managed persistence, the Fast Track to EJB 3.2 (JEE 7 level) and JPA2 course is a natural next step. It adds the EJB side to the persistence topics. If you then expose entities as web services, Developing RESTful Services Using Java Version 2.0 covers that layer.

Organizations working with specific Java or persistence versions can ask about customized private training, delivered onsite or live online, through a training proposal request.

Illustrative scenarios

The scenarios below are illustrations of how the course material can be applied. They are not descriptions of specific organizations or of the course's lab exercises.

  • Order management. A team might model an order with line items as a bidirectional one-to-many relationship. This touches the owning side, cascading, orphanRemoval, and a fetch join so a list screen does not load line items row by row.
  • Concurrent edits. A team might let users edit a record in a form while others change it. Detached instances, @Version and optimistic locking decide whether the second save fails cleanly or silently overwrites the first.
  • Search and reporting. A team might build a search screen with optional filters using the Criteria API and Predicates. Beside it, aggregate and projection JPQL queries could feed summary reports, with named queries for the stable ones.

AI coding assistants with JPA

AI coding assistants are useful for boilerplate: entity classes with @Id and @Column, embeddables, simple JPQL and named queries, and first drafts of DAO classes. They also help translate a table design into annotations.

They fail where JPA behavior depends on context the assistant cannot see:

  • Bidirectional relationships generated without a clear owning side, or with cascade settings that delete more than intended.
  • Fetch strategies that look correct but trigger extra queries or lazy-loading errors outside a transaction.
  • Persistence context and transaction assumptions in the wrong place, such as mixing resource-local and JTA patterns, or treating detached entities as managed.
  • JPQL strings that compile but fail at runtime, and Criteria code that is verbose and subtly wrong.
  • Annotation packages or API usage that do not match the persistence version in your project.

To verify, turn on the provider's SQL logging (a topic in the mappings module) and read the statements actually issued. Run tests against a real database, check entity state transitions explicitly, and write a test that forces an optimistic-lock conflict. Review generated cascade and fetch settings line by line.

Frequently asked questions

What level is this course?

Introductory. It starts with persistence layers, ORM and JDBC, then moves through mappings, queries, lifecycle, relationships, inheritance, the Criteria API and best practices over three days.

What should I know beforehand?

One year of Java programming experience, or equivalent, is preferred. Basic familiarity with relational databases and SQL is useful for the query and mapping topics.

Does it cover JPA 2 features, or only the basics?

The syllabus includes the JPA 2 items: generic queries, orphanRemoval, element collections, the Criteria API and Bean Validation. The description also says it suits users of the 1.0 release.

Are EJB and Spring integration covered?

The syllabus has optional integration modules covering Java SE with DAOs, EJB session beans with container-managed entity managers, Java web applications, and Spring. The core of the course is JPA itself.

Can this be delivered privately and customized?

Yes. HSG delivers private training for organizations onsite or live online, and content can be customized, including to the technology versions your team uses. Use the training proposal request to describe your needs.

Training locations

Fast Track to the Java Persistence API Version 2 (JPA 2) training across the U.S. and beyond.

We provide private Fast Track to the Java Persistence API Version 2 (JPA 2) training for organizations, onsite at your location or live online, throughout the United States and internationally.

View all Fast Track to the Java Persistence API Version 2 (JPA 2) training locations

Train your team with HSG

Private, instructor-led training customized for your organization.

  • Onsite or live online delivery
  • Customized curriculum
  • For a single employee or an entire team
  • Flexible scheduling
  • Experienced instructors
Request Group Training

Questions? Call us at 303.377.6176
or email info@hartmannsoftware.com

Ready to train your team?

Let's customize this training for your organization.

Tell us about your employees, your goals, and your preferred schedule. We'll prepare a training proposal covering scope, delivery format, and pricing.