Notice: this Wiki will be going read only early in 2024 and edits will no longer be 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 Java SE
- 1.4.11 Using JPA in Java EE
- 1.4.12 Using JPA in Spring
- 1.4.13 Advanced Mappings
- 1.4.14 Native API
- 1.4.15 Advanced Querying
- 1.4.16 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
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