Java Persistence Training (JPA2)

Course Number:

NTJVA205

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.

Audience:

Course Duration:
3 Days

Prerequisites:

This course concisely covers everything you need to know to begin working with the Java Persistence API. All the important concepts necessary to access and update data stored in relational databases are reviewed and an extensive series of labs is included to exercise all major capabilities.

Course Objectives:
  • Understand the JPA architecture
  • Create JPA based applications
  • Understand and use JPA to map persistent objects to the database
  • Create JPA persistence units and understand JPA persistence contexts and the entity lifecycle
  • Use the JPA EntityManager
  • Work with queries and JPQL (Java Persistence Query Language) as well as the Criteria API (JPA 2)
  • Understand and work with collections and associations
  • Use versioning support for optimistic locking
  • Map inheritance hierarchies using JPA
  • Performance tune your JPA applications
  • Understand JPA transaction support
  • Understand the relationship between JPA / EJB3
  • Use JPA entities from session beans (Optional)
  • Be familiar with Spring support for JPA (Optional)
Course Outline:
  • Understand the JPA architecture
  • Create JPA based applications
  • Understand and use JPA to map persistent objects to the database
  • Create JPA persistence units and understand JPA persistence contexts and the entity lifecycle
  • Use the JPA EntityManager
  • Work with queries and JPQL (Java Persistence Query Language) as well as the Criteria API (JPA 2)
  • Understand and work with collections and associations
  • Use versioning support for optimistic locking
  • Map inheritance hierarchies using JPA
  • Performance tune your JPA applications
  • Understand JPA transaction support
  • Understand the relationship between JPA / EJB3
  • Use JPA entities from session beans (Optional)
  • Be familiar with Spring support for JPA (Optional)

Prerequisites

Students should be proficient is OOP (Object-Oriented Programming) and Java.

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 versus 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
      • 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 Embeddable
  • The 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
  • 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
      • Lazy Loading – Open EntityManager in View Pattern
    • Integration with Spring (Optional)
      • Injection of EntityManger, EntityManagerFactory
      • LocalEntityManagerFactoryBean
      • JPA/Spring Based DAO

Related Posts

About Us

IT Training, Agile Ways of Working and High Impact Talent Development Strategies

Let Us Come to You!

Classes recently delivered in: Atlanta, Boston, Chicago, Columbus, Dallas, Detroit, Indianapolis, Jerusalem, London, Milan, New York, Palo Alto, Phoenix, Pittsburgh, Portland, Raleigh, San Antonio, San Diego, San Francisco, San Jose, Seattle, Springfield, Mass., St. Louis, Tampa and more!