Java Persistence API (JPA) - A Brief Overview

28
Java Persistence API (JPA) A Brief Overview By Scott Rabon

description

This is a lightning presentation given by Scott Rabon, a member of my development team. He presents a high level overview of the JPA based on his first exposure to it.

Transcript of Java Persistence API (JPA) - A Brief Overview

Page 1: Java Persistence API (JPA) - A Brief Overview

Java Persistence API (JPA)

A Brief Overview

By Scott Rabon

Page 2: Java Persistence API (JPA) - A Brief Overview

We have come a long way

• Java application persistence history

– JDBC

– EJB Entity Beans

1

Page 3: Java Persistence API (JPA) - A Brief Overview

Industry answered the call

• Proprietary persistence products were introduced

– JBoss Hibernate

– Oracle Top Link

2

Page 4: Java Persistence API (JPA) - A Brief Overview

Why Another Standard

• Standard goes deeper than a product

• Can be implemented by different vendors

• Developers code to interface, not implementation

3

Page 5: Java Persistence API (JPA) - A Brief Overview

A Standard Is Born

JSR 220 – EJB 3.0 Specification

Java Persistence API part of EJB 3.0 Specification

4

Page 6: Java Persistence API (JPA) - A Brief Overview

JPA Fun Facts

• JSR 220 formed May 2003

• Released May 2006

• Expert group consisted of industry ORM developers

5

Page 7: Java Persistence API (JPA) - A Brief Overview

JPA – Designed for Ease of Use

• Main goal of design team

• Elegant, powerful and flexible

• Easy to learn

6

Page 8: Java Persistence API (JPA) - A Brief Overview

Aspects: POJO Persistence

• Objects are POJO’s

• Mapping is metadata driven

• External XML or annotation based

7

Page 9: Java Persistence API (JPA) - A Brief Overview

Aspects: Non Intrusiveness

• API does not intrude on objects

• API exists as a separate layer from persistent objects

• Objects are “unaware” of the API

8

Page 10: Java Persistence API (JPA) - A Brief Overview

Aspects: Object Queries

• Query across entities and relationships

• Expressed in Java Persistence Query Language (JPQL)

• Uses a schema abstraction

9

Page 11: Java Persistence API (JPA) - A Brief Overview

Aspects: Mobile Entities

• Detachment Model• Move entities

between JVM’s• Can change state

anywhere along the way

• Reattach upon return

10

Page 12: Java Persistence API (JPA) - A Brief Overview

Aspects: Simple Configuration

• Java SE 5 Annotations

• XML

• Heavy use of defaults

11

Page 13: Java Persistence API (JPA) - A Brief Overview

Aspects: Integration and Testability

• Challenge: Testing on an app server

• API works outside application server– Two tier apps– Unit tests and

automated testing frameworks

12

Page 14: Java Persistence API (JPA) - A Brief Overview

Entities

Not same as entity beans

13

Page 15: Java Persistence API (JPA) - A Brief Overview

Entity Characteristics - Persistability

• Entities must be persistable

• State can be represented in a data store

• Entities can be manipulated without having persistent repercussions – app must use API

14

Page 16: Java Persistence API (JPA) - A Brief Overview

Entity Characteristics - Identity

• Key that uniquely identifies an instance

• Persistent identity

• Equivalent to primary key

15

Page 17: Java Persistence API (JPA) - A Brief Overview

Entity Characteristics - Transactionality

• Adds, updates and deletes normally occur in a transaction

• Changes succeed or fail atomically

• In memory entities

16

Page 18: Java Persistence API (JPA) - A Brief Overview

Entity Characteristics - Granularity

• Not primitives, wrappers, built-in objects

• Are business domain objects that mean something

• Should be fairly lightweight objects

17

Page 19: Java Persistence API (JPA) - A Brief Overview

Entity Manager

• Interface encapsulating most persistence functionality

• Set of managed instances is named persistence context

18

Page 20: Java Persistence API (JPA) - A Brief Overview

Queries

• Use JPQL syntax

• Can be defined statically (named) or dynamically

• Dynamic queries supply query criteria

19

Page 21: Java Persistence API (JPA) - A Brief Overview

JPA’s future - Independence

• Break free from the EJB specification

• Will get it’s own JSR for future evolution

20

Page 22: Java Persistence API (JPA) - A Brief Overview

The End

5 minutes of question time

starts now!

Page 23: Java Persistence API (JPA) - A Brief Overview

Questions

4 minutes left!

Page 24: Java Persistence API (JPA) - A Brief Overview

Questions

3 minutes left!

Page 25: Java Persistence API (JPA) - A Brief Overview

Questions

2 minutes left!

Page 26: Java Persistence API (JPA) - A Brief Overview

Questions

1 minute left!

Page 27: Java Persistence API (JPA) - A Brief Overview

Questions

30 seconds left!

Page 28: Java Persistence API (JPA) - A Brief Overview

Questions

TIME IS UP!