AM-401: Getting started with Java Persistence API (JPA) (Object/Relation Mapping) Framework

Outline

Day 1

  1. Using JPA
    1. Introduction to JPA (Persisting objects)
    2. Theory behind JPA (Transparent persistence, Idiomatic persistence)
    3. JPA Features
    4. Why JPA?
    5. Using JPA
    6. Mapping simple objects
    7. Using annotations for persistence mapping
    8. Configuring the persistence context
    9. Configuring the EntityManagerFactory
    10. Working with the EntityManager to persist objects
    11. Transactions and flushing
    12. Lab : Reading, updating and writing persistent objects
  2. Simple JPA-QL Queries
    1. Query Introduction (JPA-QL and SQL)
    2. First simple query
    3. Query API
    4. Working with positional parameters
    5. Working with named parameters
    6. Using getSingleResult()
    7. Querying value objects vs. entities
    8. Pagination using Query methods
    9. Working with Native SQL
    10. Defining and using named Queries
    11. Working with bulk updates
    12. Lab : Working with simple queries
  3. More Mapping Options
    1. Using @Table
      1. Override table mapping options
      2. Specify table name, catalog name, schema name
      3. @UniqueConstraint to add table level constraints
    2. Using @SecondaryTable to map to more than one table
    3. Using @Column
      1. Specify column name, make column nullable, unique, etc.
      2. Picking table if object mapped to more than one
    4. Using @Basic, @Lob, @Temporal, @Transient
    5. Working with lifecycle annotations
    6. Identity generation (sequence, identity keys)
    7. Lab : More Mappings options

Day 2

  1. Simple JPA Relationships
    1. Relationship theory
    2. Small OO relationship review
    3. How OO relationships are mapped to RDBMS/SQL/DDL
    4. A worked example
    5. @OneToMany Group has users
    6. @OneToOne User has ContactInfo
    7. @Embeddable ContactInfo has an address
    8. @ManyToMany Group has roles
    9. A worked example
    10. Persisting relationships (CRUD operations)
    11. The dreaded lazy init problem
    12. Lab : Simple Relationships
  2. Advanced Relationships
    1. Getting rid of join table for Group to User
      1. Adding @JoinColumn(name="FK_GROUP_ID")
    2. Changing Group to User to be bidirectional
      1. @OneToMany(mappedBy="parentGroup")
      2. @ManyToOne ()
      3. @JoinColumn(name="FK_GROUP_ID")
    3. Adding a second address to ContactInfo
      1. Add workAddress Address
      2. @Embedded
      3. @AttributeOverrides
    4. Making Group to Roles bidirectional
      1. @ManyToMany(mappedBy="roles")
    5. Making User to ContactInfo bidirectional
      1. @OneToOne
      2. RDBMS Table structure for bidirectional mappings
    6. Using @OrderBy for ordered relationships
    7. Using different collection types (Map, Collection, Set, List)
    8. Using @MapKey for maps
    9. Worked example revisted
    10. Lab : Advanced Relationships
  3. Fetching mapping options for relationships
    1. Introduction to Fetch strategies
    2. Using FetchType
    3. EAGER vs. LAZY
    4. Notes on lazy relationships
    5. Changing Group to Roles EAGER
    6. Avoiding lazy init, trade offs
    7. Lab: Working with FetchTypes
  4. Cascade mapping options for relationships
    1. Cascading operations
    2. CascadeType (ALL, MERGE, REMOVE, REFRESH)
    3. Simplyfying worked example with cascades
    4. Setting up cascades for:
      1. Group to User,
      2. User to ContactInfo,
      3. ContactInfo to PhoneNumbers
    5. Lab: Cascading operations

Day 3

  1. Options for inheritance
    1. Table per class hierarchy
    2. Table per subclass (join subclass)
    3. Table per concrete class (union subclass)
    4. Normal polymorphism (Table per concrete class w/o union subclass)
    5. Lab: Using various options for inheritance
  2. Advanced Queries and avoiding performance issues
    1. Setting up mappings
    2. Setting up relationships (Introduction)
    3. Performance concerns (performant ORM)
    4. Report queries
    5. Overriding lazy behavior with join fetch keyword
    6. Accessing caching
    7. Setting up the second level cache
    8. Working with DataSource, connection pools, JTA and CMT (redux)
    9. Lab : Relationships and Advanced Query
  3. Lock Modes, Versioning and Flush modes
    1. Optimistic locking with version and timestamp
    2. Understanding pessimistic locking with LockModeTypes
    3. Working with flushmodes
    4. Lab : Working with flush modes

Day 4

  1. JPA SQL Redux
    1. Simple Mapping Entities to SQL
    2. Simple Mapping Scalar values to SQL
    3. Using a different table
    4. Using a different table and different columns
    5. Overriding EntityMappings with @EntityResult, @SqlResultSetMapping
    6. Mapping Scalars and Entities
    7. Mapping more than one Entity
    8. Use Cases for Using JPA SQL
    9. Lab : Go Native! with JPA SQL support
  2. Writing JPA based DAO objects
    1. Keeping JPA code out of your Managers and Services
  3. Sharing a entityManager using a ThreadLocal
    1. Lab: Sharing a entityManager using a ThreadLocal
  4. Creating a Servlet filter that associates a entityManager with a request
    1. Lab: Creating a Servlet filter that associates a entityManager with a request
  5. Debugging Hibernate (R) ORM Framework with Log4j
    1. Lab: Debugging Hibernate (R) ORM Framework with Log4j
  6. Managing transactions using IoC
    1. Lab: Managing transactions using IoC
  7. Tunning your queries
    1. Lab: Tunning your queries
  8. Spring support for JPA (Optional)
    1. Quick introduction to Spring
    2. Spring simplifies JPA development
    3. Using Spring Transaction support
    4. Using Spring DAO support
    5. Design patterns for handling EntityManagers
    6. Lab : Using Spring's JPA DAO and Transactions
  9. JPA Framework and JEE (EJB and JTA) (Optional)
    1. JPA and EJB3 (Optional)
    2. Introduction to EJB3
    3. BeanTypes: Stateless Session, Message Driven, Stateful Session (related Annotations)
    4. Remote and local interfaces (related Annotations)
    5. Using JPA and EJB3 (JPA) together
    6. EJB3 and Dependency Injection
    7. Dependency Injecting JPA Persistence Context
    8. Lab EJB3 and JPA
    9. EJB3 and AOP
    10. Lab EJB3 and AOP
    11. EJB3 and Transaction Management, JTA (related Annotations)
    12. Setting up your environment
    13. Using EJB3 declaritive Transaction support
    14. Using the EntityManager
    15. Configuration
    16. Lab : Using JPA and EJB3 with Declaritive transactions

Day 5 (Optional)

  1. JPA/Hibernate (R) ORM Framework Caching
    1. Caching overview
    2. Caching Architecture
    3. API to control cache
    4. Caching strategies
    5. Working with EHCache
    6. Lab : Using EHCache to enhance performance
    7. Working with JBoss (R) TreeCache (Optional)
    8. Lab : Setting up a distributed cache cluster for enterprise applications
  2. Advanced Using SQL to take control of Hibernate
    1. Using the subselect method
    2. Working with multiple tables
    3. Overriding CRUD operation with SQL
    4. Lab: Accessing multiple tables for a single listing
    5. Lab: Turning delete into a soft delete
    6. Native SQL for named queries
  3. Using a SQLQuery
  4. Working with Alias and property references
  5. Specifying column/alias names
  6. Using stored procedures for querying
    1. Lab: Writing a complex SQL query that spans relationships
    2. Lab: Using a stored procedure
  7. Working with Hibernate (R) ORM Framework Filters (Optional)
    1. Lab Working with Hibernate (R) ORM Framework filters to implement row-level security
  8. Working with Hibernate (R) ORM Framework to get XML from the database (Optional)
    1. Introduction to DOM4J
    2. Mapping an entity to elements
    3. Lab Gettting a DOM from a complex relationship
  9. Hibernate (R) ORM Framework Eclipse Tools (Optional)
    1. Setting up the environment
    2. Create Hibernate (R) ORM Framework configuration file
    3. Code generation
    4. Exporters
    5. Controlling reverse engineering
    6. Lab Using Hibernate (R) ORM Framework Eclipse Tools
  10. Hibernate (R) ORM Framework Ant Tools (Optional)
    1. Setting up the environment
    2. Using with EJB3
    3. Using with JDBC
    4. Annotation based
    5. Mapping file based
    6. Database schema exporter
    7. Java code exporter
    8. Mapping file exporter
    9. Query exporter
    10. Documentation exporter
    11. Controlling reverse engineering
    12. Lab Using Ant Tools