.:An Endless Journey:.
open source and me
  • Immutable Page
  • Info
  • Attachments

Mastering JPA

Objective of this documentation.

  1. Organize my notes on JPA
  2. Try to compile a comprehensive material on the topic by combining existing documents and my notes

Hopefully, it will provides:

  • Overview of various topics in JPA programming
  • Provide pointers for each topics
  • Filling-in the missing pieces

What is ORM

ORM stands for object-relational-mapping. It is a technology emerged to overcome the object-relational impendance mismatch problem. See The Object-Relation Impedance Mismatch for good starting point on this topic.

What is JPA

Specification of a standard ORM framework. From the perspective of application programmers, it consists of the following elements:

  • Annotation for defining ORM model
  • Conceptual definitions (Persistence Unit, Persistence Context)
  • API for manipulate with persistable objects (EntityManager and Query)

  • Query language for performing queries. (EJB-QL)

Getting Started

To get a taste of what to be provided by JPA, try reading the tutorial briefly.

In order to develop application with JPA, you will have the following steps which should be answered first

  1. Determine kind of configuration
  2. Setup the JPA environment properly
  3. Define some unit-of-work and the object model (aka domain model)
  4. Code the classes with annotations, and appropriate finder methods
  5. Write the persistence.xml

Configuration alternatives

Major choices:

  1. Container Managed / Application Managed
  2. JTA bound EM, Resource Local EM
  3. Extended PC propagation

Defining the mapping

When defining the mapping, generally you need to consider the association between entities.

  • Identify classes (key, and supplementary)
  • Multipicity (OneToOne, OneToMany, ManyToOne, ManyToMany)

  • Multi-value semantics (Collection / Set / List)
  • Association (Navigation: Uni-direction / Bi-direction)
  • Owning Side and inverse side
  • Eager pre-fetch and Lazy load

Transaction and Concurrency Issue

  • Use of Optimistic lock (@Version)
  • JTA and JPA

Performance Issue

  • Use 'lazy' by default

Other Issue

  • Schema Create and Update
  • Data Migration

Reference and Resources

Introduction to ORM topics

JPA Tutorial

Specification

Official Documentation for well-known JPA providers

Quick Reference