AM-401: Getting started with Java Persistence API (JPA) (Object/Relation Mapping) Framework
Outline
Day 1
- Using JPA
- Introduction to JPA (Persisting objects)
- Theory behind JPA (Transparent persistence, Idiomatic persistence)
- JPA Features
- Why JPA?
- Using JPA
- Mapping simple objects
- Using annotations for persistence mapping
- Configuring the persistence context
- Configuring the EntityManagerFactory
- Working with the EntityManager to persist objects
- Transactions and flushing
- Lab : Reading, updating and writing persistent objects
- Simple JPA-QL Queries
- Query Introduction (JPA-QL and SQL)
- First simple query
- Query API
- Working with positional parameters
- Working with named parameters
- Using getSingleResult()
- Querying value objects vs. entities
- Pagination using Query methods
- Working with Native SQL
- Defining and using named Queries
- Working with bulk updates
- Lab : Working with simple queries
- More Mapping Options
- Using @Table
- Override table mapping options
- Specify table name, catalog name, schema name
- @UniqueConstraint to add table level constraints
- Using @SecondaryTable to map to more than one table
- Using @Column
- Specify column name, make column nullable, unique, etc.
- Picking table if object mapped to more than one
- Using @Basic, @Lob, @Temporal, @Transient
- Working with lifecycle annotations
- Identity generation (sequence, identity keys)
- Lab : More Mappings options
Day 2
- Simple JPA Relationships
- Relationship theory
- Small OO relationship review
- How OO relationships are mapped to RDBMS/SQL/DDL
- A worked example
- @OneToMany Group has users
- @OneToOne User has ContactInfo
- @Embeddable ContactInfo has an address
- @ManyToMany Group has roles
- A worked example
- Persisting relationships (CRUD operations)
- The dreaded lazy init problem
- Lab : Simple Relationships
- Advanced Relationships
- Getting rid of join table for Group to User
- Adding @JoinColumn(name="FK_GROUP_ID")
- Changing Group to User to be bidirectional
- @OneToMany(mappedBy="parentGroup")
- @ManyToOne ()
- @JoinColumn(name="FK_GROUP_ID")
- Adding a second address to ContactInfo
- Add workAddress Address
- @Embedded
- @AttributeOverrides
- Making Group to Roles bidirectional
- @ManyToMany(mappedBy="roles")
- Making User to ContactInfo bidirectional
- @OneToOne
- RDBMS Table structure for bidirectional mappings
- Using @OrderBy for ordered relationships
- Using different collection types (Map, Collection, Set, List)
- Using @MapKey for maps
- Worked example revisted
- Lab : Advanced Relationships
- Fetching mapping options for relationships
- Introduction to Fetch strategies
- Using FetchType
- EAGER vs. LAZY
- Notes on lazy relationships
- Changing Group to Roles EAGER
- Avoiding lazy init, trade offs
- Lab: Working with FetchTypes
- Cascade mapping options for relationships
- Cascading operations
- CascadeType (ALL, MERGE, REMOVE, REFRESH)
- Simplyfying worked example with cascades
- Setting up cascades for:
- Group to User,
- User to ContactInfo,
- ContactInfo to PhoneNumbers
- Lab: Cascading operations
Day 3
- Options for inheritance
- Table per class hierarchy
- Table per subclass (join subclass)
- Table per concrete class (union subclass)
- Normal polymorphism (Table per concrete class w/o union subclass)
- Lab: Using various options for inheritance
- Advanced Queries and avoiding performance issues
- Setting up mappings
- Setting up relationships (Introduction)
- Performance concerns (performant ORM)
- Report queries
- Overriding lazy behavior with join fetch keyword
- Accessing caching
- Setting up the second level cache
- Working with DataSource, connection pools, JTA and CMT (redux)
- Lab : Relationships and Advanced Query
- Lock Modes, Versioning and Flush modes
- Optimistic locking with version and timestamp
- Understanding pessimistic locking with LockModeTypes
- Working with flushmodes
- Lab : Working with flush modes
Day 4
- JPA SQL Redux
- Simple Mapping Entities to SQL
- Simple Mapping Scalar values to SQL
- Using a different table
- Using a different table and different columns
- Overriding EntityMappings with @EntityResult, @SqlResultSetMapping
- Mapping Scalars and Entities
- Mapping more than one Entity
- Use Cases for Using JPA SQL
- Lab : Go Native! with JPA SQL support
- Writing JPA based DAO objects
- Keeping JPA code out of your Managers and Services
- Sharing a entityManager using a ThreadLocal
- Lab: Sharing a entityManager using a ThreadLocal
- Creating a Servlet filter that associates a entityManager with a request
- Lab: Creating a Servlet filter that associates a entityManager with a request
- Debugging Hibernate (R) ORM Framework with Log4j
- Lab: Debugging Hibernate (R) ORM Framework with Log4j
- Managing transactions using IoC
- Lab: Managing transactions using IoC
- Tunning your queries
- Lab: Tunning your queries
- Spring support for JPA (Optional)
- Quick introduction to Spring
- Spring simplifies JPA development
- Using Spring Transaction support
- Using Spring DAO support
- Design patterns for handling EntityManagers
- Lab : Using Spring's JPA DAO and Transactions
- JPA Framework and JEE (EJB and JTA) (Optional)
- JPA and EJB3 (Optional)
- Introduction to EJB3
- BeanTypes: Stateless Session, Message Driven, Stateful Session (related Annotations)
- Remote and local interfaces (related Annotations)
- Using JPA and EJB3 (JPA) together
- EJB3 and Dependency Injection
- Dependency Injecting JPA Persistence Context
- Lab EJB3 and JPA
- EJB3 and AOP
- Lab EJB3 and AOP
- EJB3 and Transaction Management, JTA (related Annotations)
- Setting up your environment
- Using EJB3 declaritive Transaction support
- Using the EntityManager
- Configuration
- Lab : Using JPA and EJB3 with Declaritive transactions
Day 5 (Optional)
- JPA/Hibernate (R) ORM Framework Caching
- Caching overview
- Caching Architecture
- API to control cache
- Caching strategies
- Working with EHCache
- Lab : Using EHCache to enhance performance
- Working with JBoss (R) TreeCache (Optional)
- Lab : Setting up a distributed cache cluster for enterprise applications
- Advanced Using SQL to take control of Hibernate
- Using the subselect method
- Working with multiple tables
- Overriding CRUD operation with SQL
- Lab: Accessing multiple tables for a single listing
- Lab: Turning delete into a soft delete
- Native SQL for named queries
- Using a SQLQuery
- Working with Alias and property references
- Specifying column/alias names
- Using stored procedures for querying
- Lab: Writing a complex SQL query that spans relationships
- Lab: Using a stored procedure
- Working with Hibernate (R) ORM Framework Filters (Optional)
- Lab Working with Hibernate (R) ORM Framework filters to implement row-level security
- Working with Hibernate (R) ORM Framework to get XML from the database (Optional)
- Introduction to DOM4J
- Mapping an entity to elements
- Lab Gettting a DOM from a complex relationship
- Hibernate (R) ORM Framework Eclipse Tools (Optional)
- Setting up the environment
- Create Hibernate (R) ORM Framework configuration file
- Code generation
- Exporters
- Controlling reverse engineering
- Lab Using Hibernate (R) ORM Framework Eclipse Tools
- Hibernate (R) ORM Framework Ant Tools (Optional)
- Setting up the environment
- Using with EJB3
- Using with JDBC
- Annotation based
- Mapping file based
- Database schema exporter
- Java code exporter
- Mapping file exporter
- Query exporter
- Documentation exporter
- Controlling reverse engineering
- Lab Using Ant Tools