Skip to main content

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.

Jump to: navigation, search

EclipseLink/Course/JPA/Introduction

< EclipseLink
Revision as of 11:48, 12 August 2010 by Douglas.clarke.oracle.com (Talk | contribs) (JPA Querying)

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.

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.

  1. Write a simple class with String and numeric attributes
    1. Add @Entity annotation
    2. Annotated one of the attributes as the @Id (primary-key)
  2. Populate the persistence.xml
    1. JDBC information
    2. EclipseLink logging at FINE
    3. DDL generation
  3. Build simple test case with main()
    1. Persistence.createEntityManagerFactory
    2. Create EntityManager
    3. Create sample instance of entity and persist within transaction
    4. 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.

  1. Map Employee model using: M:1, 1:M, M:M, Embeddable, and Inheritance
  2. Use example provided test harness to validate mappings

JPA Querying

Basic JPA 1.0 querying.

  • Find
  • JPQL
  • Dynamic Queries
  • Named Queries
  • Query Hints

Exercise #3: Querying the Employee Model

JPA Transaction

EclipseLink Caching

Using JPA in Java SE

Using JPA in Java EE

Using JPA in Spring

Advanced Mappings

Native API

Advanced Querying

Performance and Scalability

Back to the top