Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
EclipseLink/Course/JPA/Introduction
Course: Introduction to EclipseLink JPA
This course introduces developers to JPA and more specifically using JPA with EclipseLink as the provider and many of its advanced features.
The course is designed to be a 2-day session with a mix of presentation materials as well as exercises.
License
The course materials are developed within the EclipseLink projects under the Creative Commons Attribution-Share Alike 3.0 (Unported) License as per the Approved Licenses for Non-Code and Example Content.
Contents
- 1 Course: Introduction to EclipseLink JPA
- 1.1 Course Goals
- 1.2 Prerequisites
- 1.3 Materials
- 1.4 Outline
- 1.4.1 EclipseLink Project Overview
- 1.4.2 JPA Basics
- 1.4.3 Exercise #1: My First Entity
- 1.4.4 JPA Mapping
- 1.4.5 Exercise #2: Employee Mapping
- 1.4.6 JPA Querying
- 1.4.7 Exercise #3: Querying the Employee Model
- 1.4.8 JPA Transaction
- 1.4.9 EclipseLink Caching
- 1.4.10 Using JPA in Containers
- 1.4.11 Advanced Mappings
- 1.4.12 Native API
- 1.4.13 Advanced Querying
- 1.4.14 Performance and Scalability
Course Goals
The goals of the course are to:
- Introduce developers to EclipseLink and JPA
- Develop core skills in configuring and using JPA in Java SE and EE
- Introduce common extended functionality of the EclipseLink JPA implementation
At the end of the course the developer should, through lecture and practical exercises, leave with a good understanding of EclipseLink JPA and the information necessary to lookup additional capabilities and apply them as needed.
Prerequisites
The course targets developers with good knowledge of Java and Java EE development and a basic understanding of relational databases and JDBC/SQL usage.
Exercises
The exercises can be done in any development environment that supports JPA but the documented steps will be based on the Eclipse Helios release of the IDE for Java EE developers.
Materials
The course materials are being developed in the EclipseLink SVN (here).
Outline
EclipseLink Project Overview
JPA Basics
- Mapping
- @Entity
- @Basic
- Persistence unit (persistence.xml)
- EntityManagerFactory
- EntityManager
- persist/find
Exercise #1: My First Entity
In this exercise the student will build the most basic of JPA entities to get a feel for the mechanics involved.
- Write a simple class with String and numeric attributes
- Add @Entity annotation
- Annotated one of the attributes as the @Id (primary-key)
- Populate the persistence.xml
- JDBC information
- EclipseLink logging at FINE
- DDL generation
- Build simple test case with main()
- Persistence.createEntityManagerFactory
- Create EntityManager
- Create sample instance of entity and persist within transaction
- Find sample entity
JPA Mapping
This section will go into greater detail of the various mappings supported by JPA 1.0 and EclipseLink JPA mappings that go beyond JPA 1.0.
Note: The JPA 2.0 mappings will be covered later in the advanced section (13).
- Mapping Concepts
- Configuration by exception
- Lazy loading
- Identity: @Id, @IdClass
- Basic Mappings
- @Column
- fetch=LAZY
- Temporal
- @Lob
- Relationship Mappings
- @OneToOne/@ManyToOne
- @OneToMany
- @ManyToMany
- Inheritance
- Embeddable
- @MappedSuperclass
Exercise #2: Employee Mapping
More advanced mapping of the Employee demo using annotations.
- Map Employee model using: M:1, 1:M, M:M, Embeddable, and Inheritance
- Use example provided test harness to validate mappings
JPA Querying
Basic JPA 1.0 querying.
- Find
- JPQL
- Dynamic Queries
- Named Queries
- EntityManager.refresh
- Query Hints
Exercise #3: Querying the Employee Model
JPA Transaction
Basic JPA transactions
- JTA or RESOURCE_LOCAL
- EntityManager operations
- persist
- merge
- remove
- refresh
- Mapping cascade options
- @PrivateOwned
EclipseLink Caching
- Caching Basics
- Shared/Isolated/TXN
- Configuration
- Defaults using PU properties
- PUproperties per entity
- @Cache
- eclipselink-orm.xml
- IdentityMapAccessor
- Cache Coordination
Using JPA in Containers
This section goes into how EclipseLink JPA is used and integrated with various containers.
- Application vs Container Managed JPA
- Data Sources
- Weaving
- Configuration Options
- Java SE
- Container Managed Persistence
- EM/EMF Injection
- EM/EMF lookup in JNDI
- JTA transactions
- Extended Persistence Context and join
Advanced Mappings
- Converters
- JPA 2.0
- Metamodel
- Canonical Metamodel
Native API
- Native Meta Model
- ClassDescriptor and policies
- Mappings
- Login & Connector
- Sessions
- ServerSession and ClientSession
- DatabaseSession
- SessionBroker
- Customization
- Session Customizer
- Descriptor Customizer
- Event Listeners
- Session Event Listener
- Descripto Event Listener
- Native Configuration
- sessions.xml
- deployment XML
- eclipselink-orm.xml
- eclipselink-oxm.xml
Advanced Querying
- Query Hints
- Native queries and Expressions
- Query redirectors and events
- Criteria API (JPA 2.0)
Performance and Scalability
- Optimizing Entity Loading
- Fetch & Batch Loading
- Partial Entities using AttributeGroup
- FetchGroup
- LoadGroup
- CopyGroup
- Merge