SlideShare a Scribd company logo
<Insert Picture Here>
Using the Latest Java Persistence API 2.0 Features
Arun Gupta, Java EE & GlassFish Guy
blogs.sun.com/arungupta, @arungupta
2
The following/preceding is intended to outline our
general product direction. It is intended for
information purposes only, and may not be
incorporated into any contract. It is not a
commitment to deliver any material, code, or
functionality, and should not be relied upon in
making purchasing decisions.
The development, release, and timing of any
features or functionality described for Oracle’s
products remains at the sole discretion of Oracle.
3
Java Persistence API
Object/Relational Mapping for Java Developers
• The standard API for object/relational persistence for
Java SE and Java EE applications
• Automatic mapping from Java object domain model to
relational database
• Mapping is explicit, not “magic”
• Uses annotations and/or XML
• Many useful defaults
• Lots of hooks and options for customization
• SQL-like query language (JPQL)
• Applied to domain model
• Supports both static and dynamic queries
4
Background
• JPA 1.0
• Introduced as part of Java EE 5; also available standalone
• Part of the EJB 3.0 simplification effort
• Based on experience with existing technology:
• TopLink, Hibernate, JDO
• Covered all the essentials++
5
JPA 2.0 (JSR 317)
• JPA 2.0
• Part of Java EE 6 and/or available standalone
• Adds more sophisticated mapping and modeling options
• Expanded query language
• Adds Criteria API, together with Metamodel API
• Support for Validation
• EclipseLink is reference implementation
• Integrated in GlassFish
6
Object/Relational Mapping
Essentials
• Entities
• Basic types
• Strings, integers, floats, decimals, …
• Embeddable classes
• E.g., Address
• Relationships
• One-to-one, one-to-many/many-to-one, many-to-many
• Collections modeled with java.util Collection, Set, List, or Map
• Customized via metadata: @JoinColumn, @JoinTable, etc.
• Inheritance
• Single table, joined subclass, table per class (optional)
7
Object/Relational Mapping
New in JPA 2.0
• Element collections
• Collections of strings, integers, floats, decimals, …
• Collections of embeddable classes
• Embeddable classes
• Nested embeddables; embeddables with relationships
• Persistently ordered lists
• Improved Map support
• More relationship mapping options
• Unidirectional one-many foreign key mappings
• Join table mappings for one-one, one-many/many-one
8
Collections of Basic Types
@Entity
public class Person {
@Id protected String ssn;
protected String name;
protected Date birthDate;
. . .
@ElementCollection
protected Set<String> nickNames;
}
9
Collections of Basic Types
@Entity
public class Person {
@Id protected String ssn;
protected String name;
protected Date birthDate;
. . .
@ElementCollection
@CollectionTable(name=”ALIAS”)
protected Set<String> nickNames;
}
10
Collection of Embeddable Types
@Embeddable public class Address {
String street;
String city;
String state;
. . .
}
@Entity public class RichPerson extends Person {
. . .
@ElementCollection
protected Set<Address> vacationHomes;
. . .
}
11
Multiple Levels of Embedding
@Entity public class Employee {
@Id int empId;
String name;
ContactInfo contactInfo;
. . .
}
@Embeddable public class ContactInfo {
@Embedded Address address;
. . .
}
12
Embeddables with Relationships
@Entity public class Employee {
@Id int empId;
String name;
ContactInfo contactInfo;
. . .
}
@Embeddable public class ContactInfo {
@Embedded Address address;
@OneToMany Set<Phone> phones;
. . .
}
13
Ordered Lists
@Entity public class CreditCard {
@Id long cardNumber;
@OneToOne Person cardHolder;
. . .
@OneToMany
@OrderColumn
List<CardTransaction> transactions;
}
14
Maps
@Entity public class VideoStore {
@Id Integer storeId;
Address location;
. . .
@ElementCollection
Map<Movie, Integer> inventory;
}
@Entity public class Movie {
@Id String title;
@String director;
. . .
}
15
Automatic Orphan Deletion
For entities logically “owned” by “parent”
@Entity public class Order {
@Id int orderId;
. . .
@OneToMany(cascade=PERSIST, orphanRemoval=true)
Set<Item> lineItems;
. . .
}
16
Key Interfaces
• EntityManagerFactory
• Used to create entity managers
• One entity manager factory per persistence unit
• EntityManager
• Used to manage persistence context
• Entities read/written from database
• Operations: persist, remove, find, refresh, createQuery,…
• Query, TypedQuery
• Used for query configuration, parameter binding, query
execution
17
Java Persistence Query Language
• String-based SQL-like query language
• SELECT, FROM, WHERE, GROUP BY, ORDER BY,…
• Queries written over Java domain model
• Entities, state, relationships
• Supports navigation using dot-notation
• Mapped into SQL by the provider
• Supports static and dynamic use
SELECT AVG (p.price)
FROM Order o JOIN o.products p
WHERE o.customer.address.zip = ‘94301’
18
Java Persistence Query Language
New in JPA 2.0
• Support for all new modeling and mapping features
• Operators and functions in select list
• Case, coalesce, nullif expressions
• Restricted polymorphism
• Collection-valued parameters for IN-expressions
19
JPQL New Operators
INDEX
For ordered Lists
KEY, VALUE, ENTRY
For maps
CASE, COALESCE, NULLIF
For case expressions, etc.
TYPE
For restricted polymorphism
20
Ordered Lists
SELECT t
FROM CreditCard c JOIN c.transactions t
WHERE c.cardHolder.name = 'John Doe'
AND INDEX(t) < 10
21
Maps
// Inventory is Map<Movie, Integer>
SELECT v.location.street, KEY(i).title, VALUE(i),
FROM VideoStore v JOIN v.inventory i
WHERE KEY(i).director LIKE '%Hitchcock%'
AND VALUE(i) > 0
22
Case Expressions
UPDATE Employee e
SET e.salary =
CASE e.rating
WHEN 1 THEN e.salary * 1.05
WHEN 2 THEN e.salary * 1.02
ELSE e.salary * 0.95
END
23
Restricted Polymorphism
SELECT e
FROM Employee e
WHERE TYPE(e) IN :empTypes
24
Metamodel
• Abstract “schema-level” view of managed classes
• Entities, mapped superclasses, embeddables
• Accessed dynamically
• EntityManagerFactory.getMetamodel()
• EntityManager.getMetamodel()
• And/or materialized as static metamodel classes
• Used to create strongly-typed criteria queries
• Spec defines canonical format
25
import javax.persistence.metamodel.*;
@StaticMetamodel(Customer.class)
public class Customer_ {
public static SingularAttribute<Customer, Integer> custId;
public static SingularAttribute<Customer, String> name;
public static SingularAttribute<Customer, Address> address;
public static SingularAttribute<Customer, SalesRep> rep;
public static SetAttribute<Customer, Order> orders;
}
Java Persistence API 2
Metamodel Example
@Entity
public class Customer {
@Id Integer custId;
String name;
...
Address address;
@ManyToOne SalesRep rep;
@OneToMany Set<Order> orders;
}
26
javac -processor
org.eclipse.persistence.internal.jpa.modelgen.CanonicalM
odelProcessor -sourcepath src -d src -classpath
/ace2_apps/eclipselink/jlib/eclipselink.jar:.:/ace2_apps
/eclipselink/jlib/JPA/javax.persistence_2.0.0.v200911271
158.jar -proc:only
-Aeclipselink.persistencexml=src/META-
INF/persistence.xml src/demo/*.java
Note: Creating the metadata factory …
Note: Building metadata class for round element:
demo.Item
. . .
http://weblogs.java.net/blog/lancea/archive/2009/12/15/generating-jpa-20-static-metamodel-classes-using-eclipselink-20-and-n
Metamodel using CLI
27
Canonical Metamodel using NetBeans
http://blogs.sun.com/arungupta/entry/totd_148_jpa2_metamodel_classes
28
Criteria API
New in JPA 2.0
• Object-based API for building queries
• Designed to mirror JPQL semantics
• Strongly typed
• Based on type-safe metamodel of persistent classes and
relationships
• Heavy use of Java generics
• Supports object-based or string-based navigation
• Query construction at development time or runtime
29
Criteria API: Core Interfaces
• CriteriaBuilder
• Construct criteria queries, selections, predicates, orderings
• CriteriaQuery
• Used to add / replace/ browse query elements
• from, select, where, orderBy, groupBy, having,… methods
• Root
• Query roots
• Join, ListJoin, MapJoin, …
• Joins from a root or existing join
• Path
• Navigation from a root, join, or path
• Subquery
30
How to Build a Criteria Query
EntityManager em = emf.createEntityManager();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery criteria = builder.createQuery(Manufacturer.class);
Root root = criteria.from(Manufacturer.class); // FROM clause
criteria.select(root); // SELECT clause
Predicate condition = builder.like(root.get(Manufacturer_.name),
"%" + name + "%");
criteria.where(condition); // WHERE clause
TypedQuery query = em.createQuery(criteria); // FIRE query
List manufacturers = query.getResultList();
31
Validation
New in JPA 2.0
• Leverages work of Bean Validation (JSR 303)
• Automatic validation upon lifecycle events
• PrePersist
• PreUpdate
• PreRemove
• Validation-mode element in “persistence.xml”
• AUTO, CALLBACK, NONE
• NetBeans 7.0 M2 generates the constraints
32
Concurrency
• Java Persistence assumes optimistic concurrency
• Short-term read locks
• Long-term write locks
• Provider can defer writing to database to transaction commit
• Application can flush to database on demand
• Optimistic “locking” done via version attributes
• Integral or timestamp attributes, managed by provider
• Provider validates version when writing to database
• Explicit lock() calls available to validate read data
33
Pessimistic Locking
New in JPA 2.0
• Java Persistence assumes optimistic concurrency
• Normal pessimistic locking
• Persistent state of entity
• Relationships, Element collections
• Grab database locks upfront
• JPA spec defines semantics, not mechanism
• Provider can lock more (not less)
• Lock modes
• PESSIMISTIC_READ – grab shared lock
• PESSIMISTIC_WRITE – grab exclusive lock
• PESSIMISTIC_FORCE_INCREMENT – update version
34
Locking APIs
• EntityManager methods: lock, find, refresh
• Query / TypedQuery methods: setLockMode, setHint
• NamedQuery annotation: lockMode element
• javax.persistence.lock.scope property
• javax.persistence.lock.timeout hint
• PessimisticLockException (if transaction rolls back)
• LockTimeoutException (if only statement rolls back)
35
Caching Configuration
New in JPA 2.0
• EntityManager persistence context corresponds to
“first level” cache
• Entities managed by persistence provider
• Entities read from database
• Entities to be written to database
• Most implementations also use second-level caches
• Not always transparent to application
• JPA 2.0 standardizes basic second-level cache
options
36
Standard Configuration Properties
• javax.persistence.jdbc.driver
• javax.persistence.jdbc.url
• javax.persistence.jdbc.user
• javax.persistence.jdbc.password
• . . .
37
Summary of JPA 2.0 New Features
• More flexible modeling capabilities
• Expanded O/R mapping functionality
• Additions to Java Persistence query language
• Criteria API
• Metamodel API
• Pessimistic locking
• Support for validation
• Standardization of many configuration options
<Insert Picture Here>
Using the Latest Java Persistence API 2.0 Features
Arun Gupta, Java EE & GlassFish Guy
blogs.sun.com/arungupta, @arungupta

More Related Content

What's hot

5050 dev nation
5050 dev nation5050 dev nation
5050 dev nation
Arun Gupta
 
Sun Java EE 6 Overview
Sun Java EE 6 OverviewSun Java EE 6 Overview
Sun Java EE 6 Overview
sbobde
 
Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011
Arun Gupta
 
Java 7 workshop
Java 7 workshopJava 7 workshop
Java 7 workshop
Dennis Laumen
 
Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)
Hamed Hatami
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
ejlp12
 
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
Arun Gupta
 
Java EE 6 Component Model Explained
Java EE 6 Component Model Explained Java EE 6 Component Model Explained
Java EE 6 Component Model Explained
Shreedhar Ganapathy
 
Java EE 6 & GlassFish 3
Java EE 6 & GlassFish 3Java EE 6 & GlassFish 3
Java EE 6 & GlassFish 3
Arun Gupta
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]
Ryan Cuprak
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Arun Gupta
 
Java EE6 CodeCamp16 oct 2010
Java EE6 CodeCamp16 oct 2010Java EE6 CodeCamp16 oct 2010
Java EE6 CodeCamp16 oct 2010
Codecamp Romania
 
Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010
Arun Gupta
 
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3 Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Skills Matter
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Arun Gupta
 
Java EE 7 - Overview and Status
Java EE 7  - Overview and StatusJava EE 7  - Overview and Status
Java EE 7 - Overview and Status
Java Usergroup Berlin-Brandenburg
 
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
TDC 2011: The Java EE 7 Platform: Developing for the CloudTDC 2011: The Java EE 7 Platform: Developing for the Cloud
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
Arun Gupta
 
JavaEE 6 tools coverage
JavaEE 6 tools coverageJavaEE 6 tools coverage
JavaEE 6 tools coverage
Ludovic Champenois
 
Java Summit Chennai: JAX-RS 2.0
Java Summit Chennai: JAX-RS 2.0Java Summit Chennai: JAX-RS 2.0
Java Summit Chennai: JAX-RS 2.0
Arun Gupta
 
GIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE ApplicationGIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE Application
Arun Gupta
 

What's hot (20)

5050 dev nation
5050 dev nation5050 dev nation
5050 dev nation
 
Sun Java EE 6 Overview
Sun Java EE 6 OverviewSun Java EE 6 Overview
Sun Java EE 6 Overview
 
Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011Java EE 6 workshop at Dallas Tech Fest 2011
Java EE 6 workshop at Dallas Tech Fest 2011
 
Java 7 workshop
Java 7 workshopJava 7 workshop
Java 7 workshop
 
Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)Java EE 7 (Hamed Hatami)
Java EE 7 (Hamed Hatami)
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
 
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
The Java EE 7 Platform: Productivity & HTML5 at JavaOne Latin America 2012
 
Java EE 6 Component Model Explained
Java EE 6 Component Model Explained Java EE 6 Component Model Explained
Java EE 6 Component Model Explained
 
Java EE 6 & GlassFish 3
Java EE 6 & GlassFish 3Java EE 6 & GlassFish 3
Java EE 6 & GlassFish 3
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
 
Java EE6 CodeCamp16 oct 2010
Java EE6 CodeCamp16 oct 2010Java EE6 CodeCamp16 oct 2010
Java EE6 CodeCamp16 oct 2010
 
Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010
 
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3 Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
Arun Gupta: London Java Community: Java EE 6 and GlassFish 3
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
 
Java EE 7 - Overview and Status
Java EE 7  - Overview and StatusJava EE 7  - Overview and Status
Java EE 7 - Overview and Status
 
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
TDC 2011: The Java EE 7 Platform: Developing for the CloudTDC 2011: The Java EE 7 Platform: Developing for the Cloud
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
 
JavaEE 6 tools coverage
JavaEE 6 tools coverageJavaEE 6 tools coverage
JavaEE 6 tools coverage
 
Java Summit Chennai: JAX-RS 2.0
Java Summit Chennai: JAX-RS 2.0Java Summit Chennai: JAX-RS 2.0
Java Summit Chennai: JAX-RS 2.0
 
GIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE ApplicationGIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE Application
 

Viewers also liked

Run a marathon!
Run a marathon!Run a marathon!
Run a marathon!
blueparachute
 
Past participle vs_present_participle_adjectives
Past participle vs_present_participle_adjectivesPast participle vs_present_participle_adjectives
Past participle vs_present_participle_adjectives
blueparachute
 
How to run your first marathon ? JavaOne 2014 Ignite
How to run your first marathon ? JavaOne 2014 IgniteHow to run your first marathon ? JavaOne 2014 Ignite
How to run your first marathon ? JavaOne 2014 Ignite
Arun Gupta
 
How to Train for and Run Your First Marathon
How to Train for and Run Your First MarathonHow to Train for and Run Your First Marathon
How to Train for and Run Your First Marathon
Market Edge Consulting
 
Marathon preparation for beginners
Marathon preparation for beginnersMarathon preparation for beginners
Marathon preparation for beginners
PanaEk Warawit
 
Running
RunningRunning
Running
Jeaza Sandoy
 
Presentation fast food
Presentation fast foodPresentation fast food
Presentation fast food
ysaxvh
 

Viewers also liked (7)

Run a marathon!
Run a marathon!Run a marathon!
Run a marathon!
 
Past participle vs_present_participle_adjectives
Past participle vs_present_participle_adjectivesPast participle vs_present_participle_adjectives
Past participle vs_present_participle_adjectives
 
How to run your first marathon ? JavaOne 2014 Ignite
How to run your first marathon ? JavaOne 2014 IgniteHow to run your first marathon ? JavaOne 2014 Ignite
How to run your first marathon ? JavaOne 2014 Ignite
 
How to Train for and Run Your First Marathon
How to Train for and Run Your First MarathonHow to Train for and Run Your First Marathon
How to Train for and Run Your First Marathon
 
Marathon preparation for beginners
Marathon preparation for beginnersMarathon preparation for beginners
Marathon preparation for beginners
 
Running
RunningRunning
Running
 
Presentation fast food
Presentation fast foodPresentation fast food
Presentation fast food
 

Similar to Using the latest Java Persistence API 2.0 features

Using the latest Java Persistence API 2 Features - Tech Days 2010 India
Using the latest Java Persistence API 2 Features - Tech Days 2010 IndiaUsing the latest Java Persistence API 2 Features - Tech Days 2010 India
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
Arun Gupta
 
S313431 JPA 2.0 Overview
S313431 JPA 2.0 OverviewS313431 JPA 2.0 Overview
S313431 JPA 2.0 Overview
Ludovic Champenois
 
Jpa
JpaJpa
Spring data requery
Spring data requerySpring data requery
Spring data requery
Sunghyouk Bae
 
Naver_alternative_to_jpa
Naver_alternative_to_jpaNaver_alternative_to_jpa
Naver_alternative_to_jpa
NAVER Engineering
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/Hibernate
Sunghyouk Bae
 
Optimizer percona live_ams2015
Optimizer percona live_ams2015Optimizer percona live_ams2015
Optimizer percona live_ams2015
Manyi Lu
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
JAX London
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
Eberhard Wolff
 
Java Persistence API 2.0: An Overview
Java Persistence API 2.0: An OverviewJava Persistence API 2.0: An Overview
Java Persistence API 2.0: An Overview
Sanjeeb Sahoo
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescript
Amir Barylko
 
U-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersU-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for Developers
Michael Rys
 
springdatajpa-up.pdf
springdatajpa-up.pdfspringdatajpa-up.pdf
springdatajpa-up.pdf
ssuser0562f1
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
Oscar Merida
 
New Features of JSR 317 (JPA 2.0)
New Features of JSR 317 (JPA 2.0)New Features of JSR 317 (JPA 2.0)
New Features of JSR 317 (JPA 2.0)
Markus Eisele
 
JavaOne 2014 - Supporting Multi-tenancy Applications with Java EE
JavaOne 2014 - Supporting Multi-tenancy Applications with Java EEJavaOne 2014 - Supporting Multi-tenancy Applications with Java EE
JavaOne 2014 - Supporting Multi-tenancy Applications with Java EE
Rodrigo Cândido da Silva
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptx
Dmitry Vinnik
 
Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']
Jan Helke
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
Jeevesh Pandey
 

Similar to Using the latest Java Persistence API 2.0 features (20)

Using the latest Java Persistence API 2 Features - Tech Days 2010 India
Using the latest Java Persistence API 2 Features - Tech Days 2010 IndiaUsing the latest Java Persistence API 2 Features - Tech Days 2010 India
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
 
S313431 JPA 2.0 Overview
S313431 JPA 2.0 OverviewS313431 JPA 2.0 Overview
S313431 JPA 2.0 Overview
 
Jpa
JpaJpa
Jpa
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
Naver_alternative_to_jpa
Naver_alternative_to_jpaNaver_alternative_to_jpa
Naver_alternative_to_jpa
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/Hibernate
 
Optimizer percona live_ams2015
Optimizer percona live_ams2015Optimizer percona live_ams2015
Optimizer percona live_ams2015
 
Spring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard WolffSpring Day | Spring and Scala | Eberhard Wolff
Spring Day | Spring and Scala | Eberhard Wolff
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
Java Persistence API 2.0: An Overview
Java Persistence API 2.0: An OverviewJava Persistence API 2.0: An Overview
Java Persistence API 2.0: An Overview
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescript
 
U-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for DevelopersU-SQL - Azure Data Lake Analytics for Developers
U-SQL - Azure Data Lake Analytics for Developers
 
springdatajpa-up.pdf
springdatajpa-up.pdfspringdatajpa-up.pdf
springdatajpa-up.pdf
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
New Features of JSR 317 (JPA 2.0)
New Features of JSR 317 (JPA 2.0)New Features of JSR 317 (JPA 2.0)
New Features of JSR 317 (JPA 2.0)
 
JavaOne 2014 - Supporting Multi-tenancy Applications with Java EE
JavaOne 2014 - Supporting Multi-tenancy Applications with Java EEJavaOne 2014 - Supporting Multi-tenancy Applications with Java EE
JavaOne 2014 - Supporting Multi-tenancy Applications with Java EE
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptx
 
Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 

More from Arun Gupta

5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf
Arun Gupta
 
Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019
Arun Gupta
 
Machine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and KubernetesMachine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and Kubernetes
Arun Gupta
 
Secure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using FirecrackerSecure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using Firecracker
Arun Gupta
 
Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019
Arun Gupta
 
Why Amazon Cares about Open Source
Why Amazon Cares about Open SourceWhy Amazon Cares about Open Source
Why Amazon Cares about Open Source
Arun Gupta
 
Machine learning using Kubernetes
Machine learning using KubernetesMachine learning using Kubernetes
Machine learning using Kubernetes
Arun Gupta
 
Building Cloud Native Applications
Building Cloud Native ApplicationsBuilding Cloud Native Applications
Building Cloud Native Applications
Arun Gupta
 
Chaos Engineering with Kubernetes
Chaos Engineering with KubernetesChaos Engineering with Kubernetes
Chaos Engineering with Kubernetes
Arun Gupta
 
How to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAMHow to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAM
Arun Gupta
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
Arun Gupta
 
The Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 KeynoteThe Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 Keynote
Arun Gupta
 
Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018
Arun Gupta
 
Mastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv SummitMastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv Summit
Arun Gupta
 
Top 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's LandscapeTop 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's Landscape
Arun Gupta
 
Container Landscape in 2017
Container Landscape in 2017Container Landscape in 2017
Container Landscape in 2017
Arun Gupta
 
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftJava EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Arun Gupta
 
Docker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developersDocker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developers
Arun Gupta
 
Thanks Managers!
Thanks Managers!Thanks Managers!
Thanks Managers!
Arun Gupta
 
Migrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to ContainersMigrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to Containers
Arun Gupta
 

More from Arun Gupta (20)

5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf5 Skills To Force Multiply Technical Talents.pdf
5 Skills To Force Multiply Technical Talents.pdf
 
Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019Machine Learning using Kubernetes - AI Conclave 2019
Machine Learning using Kubernetes - AI Conclave 2019
 
Machine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and KubernetesMachine Learning using Kubeflow and Kubernetes
Machine Learning using Kubeflow and Kubernetes
 
Secure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using FirecrackerSecure and Fast microVM for Serverless Computing using Firecracker
Secure and Fast microVM for Serverless Computing using Firecracker
 
Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019Building Java in the Open - j.Day at OSCON 2019
Building Java in the Open - j.Day at OSCON 2019
 
Why Amazon Cares about Open Source
Why Amazon Cares about Open SourceWhy Amazon Cares about Open Source
Why Amazon Cares about Open Source
 
Machine learning using Kubernetes
Machine learning using KubernetesMachine learning using Kubernetes
Machine learning using Kubernetes
 
Building Cloud Native Applications
Building Cloud Native ApplicationsBuilding Cloud Native Applications
Building Cloud Native Applications
 
Chaos Engineering with Kubernetes
Chaos Engineering with KubernetesChaos Engineering with Kubernetes
Chaos Engineering with Kubernetes
 
How to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAMHow to be a mentor to bring more girls to STEAM
How to be a mentor to bring more girls to STEAM
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
 
The Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 KeynoteThe Serverless Tidal Wave - SwampUP 2018 Keynote
The Serverless Tidal Wave - SwampUP 2018 Keynote
 
Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018Introduction to Amazon EKS - KubeCon 2018
Introduction to Amazon EKS - KubeCon 2018
 
Mastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv SummitMastering Kubernetes on AWS - Tel Aviv Summit
Mastering Kubernetes on AWS - Tel Aviv Summit
 
Top 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's LandscapeTop 10 Technology Trends Changing Developer's Landscape
Top 10 Technology Trends Changing Developer's Landscape
 
Container Landscape in 2017
Container Landscape in 2017Container Landscape in 2017
Container Landscape in 2017
 
Java EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShiftJava EE and NoSQL using JBoss EAP 7 and OpenShift
Java EE and NoSQL using JBoss EAP 7 and OpenShift
 
Docker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developersDocker, Kubernetes, and Mesos recipes for Java developers
Docker, Kubernetes, and Mesos recipes for Java developers
 
Thanks Managers!
Thanks Managers!Thanks Managers!
Thanks Managers!
 
Migrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to ContainersMigrate your traditional VM-based Clusters to Containers
Migrate your traditional VM-based Clusters to Containers
 

Recently uploaded

Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 

Recently uploaded (20)

Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 

Using the latest Java Persistence API 2.0 features

  • 1. <Insert Picture Here> Using the Latest Java Persistence API 2.0 Features Arun Gupta, Java EE & GlassFish Guy blogs.sun.com/arungupta, @arungupta
  • 2. 2 The following/preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
  • 3. 3 Java Persistence API Object/Relational Mapping for Java Developers • The standard API for object/relational persistence for Java SE and Java EE applications • Automatic mapping from Java object domain model to relational database • Mapping is explicit, not “magic” • Uses annotations and/or XML • Many useful defaults • Lots of hooks and options for customization • SQL-like query language (JPQL) • Applied to domain model • Supports both static and dynamic queries
  • 4. 4 Background • JPA 1.0 • Introduced as part of Java EE 5; also available standalone • Part of the EJB 3.0 simplification effort • Based on experience with existing technology: • TopLink, Hibernate, JDO • Covered all the essentials++
  • 5. 5 JPA 2.0 (JSR 317) • JPA 2.0 • Part of Java EE 6 and/or available standalone • Adds more sophisticated mapping and modeling options • Expanded query language • Adds Criteria API, together with Metamodel API • Support for Validation • EclipseLink is reference implementation • Integrated in GlassFish
  • 6. 6 Object/Relational Mapping Essentials • Entities • Basic types • Strings, integers, floats, decimals, … • Embeddable classes • E.g., Address • Relationships • One-to-one, one-to-many/many-to-one, many-to-many • Collections modeled with java.util Collection, Set, List, or Map • Customized via metadata: @JoinColumn, @JoinTable, etc. • Inheritance • Single table, joined subclass, table per class (optional)
  • 7. 7 Object/Relational Mapping New in JPA 2.0 • Element collections • Collections of strings, integers, floats, decimals, … • Collections of embeddable classes • Embeddable classes • Nested embeddables; embeddables with relationships • Persistently ordered lists • Improved Map support • More relationship mapping options • Unidirectional one-many foreign key mappings • Join table mappings for one-one, one-many/many-one
  • 8. 8 Collections of Basic Types @Entity public class Person { @Id protected String ssn; protected String name; protected Date birthDate; . . . @ElementCollection protected Set<String> nickNames; }
  • 9. 9 Collections of Basic Types @Entity public class Person { @Id protected String ssn; protected String name; protected Date birthDate; . . . @ElementCollection @CollectionTable(name=”ALIAS”) protected Set<String> nickNames; }
  • 10. 10 Collection of Embeddable Types @Embeddable public class Address { String street; String city; String state; . . . } @Entity public class RichPerson extends Person { . . . @ElementCollection protected Set<Address> vacationHomes; . . . }
  • 11. 11 Multiple Levels of Embedding @Entity public class Employee { @Id int empId; String name; ContactInfo contactInfo; . . . } @Embeddable public class ContactInfo { @Embedded Address address; . . . }
  • 12. 12 Embeddables with Relationships @Entity public class Employee { @Id int empId; String name; ContactInfo contactInfo; . . . } @Embeddable public class ContactInfo { @Embedded Address address; @OneToMany Set<Phone> phones; . . . }
  • 13. 13 Ordered Lists @Entity public class CreditCard { @Id long cardNumber; @OneToOne Person cardHolder; . . . @OneToMany @OrderColumn List<CardTransaction> transactions; }
  • 14. 14 Maps @Entity public class VideoStore { @Id Integer storeId; Address location; . . . @ElementCollection Map<Movie, Integer> inventory; } @Entity public class Movie { @Id String title; @String director; . . . }
  • 15. 15 Automatic Orphan Deletion For entities logically “owned” by “parent” @Entity public class Order { @Id int orderId; . . . @OneToMany(cascade=PERSIST, orphanRemoval=true) Set<Item> lineItems; . . . }
  • 16. 16 Key Interfaces • EntityManagerFactory • Used to create entity managers • One entity manager factory per persistence unit • EntityManager • Used to manage persistence context • Entities read/written from database • Operations: persist, remove, find, refresh, createQuery,… • Query, TypedQuery • Used for query configuration, parameter binding, query execution
  • 17. 17 Java Persistence Query Language • String-based SQL-like query language • SELECT, FROM, WHERE, GROUP BY, ORDER BY,… • Queries written over Java domain model • Entities, state, relationships • Supports navigation using dot-notation • Mapped into SQL by the provider • Supports static and dynamic use SELECT AVG (p.price) FROM Order o JOIN o.products p WHERE o.customer.address.zip = ‘94301’
  • 18. 18 Java Persistence Query Language New in JPA 2.0 • Support for all new modeling and mapping features • Operators and functions in select list • Case, coalesce, nullif expressions • Restricted polymorphism • Collection-valued parameters for IN-expressions
  • 19. 19 JPQL New Operators INDEX For ordered Lists KEY, VALUE, ENTRY For maps CASE, COALESCE, NULLIF For case expressions, etc. TYPE For restricted polymorphism
  • 20. 20 Ordered Lists SELECT t FROM CreditCard c JOIN c.transactions t WHERE c.cardHolder.name = 'John Doe' AND INDEX(t) < 10
  • 21. 21 Maps // Inventory is Map<Movie, Integer> SELECT v.location.street, KEY(i).title, VALUE(i), FROM VideoStore v JOIN v.inventory i WHERE KEY(i).director LIKE '%Hitchcock%' AND VALUE(i) > 0
  • 22. 22 Case Expressions UPDATE Employee e SET e.salary = CASE e.rating WHEN 1 THEN e.salary * 1.05 WHEN 2 THEN e.salary * 1.02 ELSE e.salary * 0.95 END
  • 23. 23 Restricted Polymorphism SELECT e FROM Employee e WHERE TYPE(e) IN :empTypes
  • 24. 24 Metamodel • Abstract “schema-level” view of managed classes • Entities, mapped superclasses, embeddables • Accessed dynamically • EntityManagerFactory.getMetamodel() • EntityManager.getMetamodel() • And/or materialized as static metamodel classes • Used to create strongly-typed criteria queries • Spec defines canonical format
  • 25. 25 import javax.persistence.metamodel.*; @StaticMetamodel(Customer.class) public class Customer_ { public static SingularAttribute<Customer, Integer> custId; public static SingularAttribute<Customer, String> name; public static SingularAttribute<Customer, Address> address; public static SingularAttribute<Customer, SalesRep> rep; public static SetAttribute<Customer, Order> orders; } Java Persistence API 2 Metamodel Example @Entity public class Customer { @Id Integer custId; String name; ... Address address; @ManyToOne SalesRep rep; @OneToMany Set<Order> orders; }
  • 26. 26 javac -processor org.eclipse.persistence.internal.jpa.modelgen.CanonicalM odelProcessor -sourcepath src -d src -classpath /ace2_apps/eclipselink/jlib/eclipselink.jar:.:/ace2_apps /eclipselink/jlib/JPA/javax.persistence_2.0.0.v200911271 158.jar -proc:only -Aeclipselink.persistencexml=src/META- INF/persistence.xml src/demo/*.java Note: Creating the metadata factory … Note: Building metadata class for round element: demo.Item . . . http://weblogs.java.net/blog/lancea/archive/2009/12/15/generating-jpa-20-static-metamodel-classes-using-eclipselink-20-and-n Metamodel using CLI
  • 27. 27 Canonical Metamodel using NetBeans http://blogs.sun.com/arungupta/entry/totd_148_jpa2_metamodel_classes
  • 28. 28 Criteria API New in JPA 2.0 • Object-based API for building queries • Designed to mirror JPQL semantics • Strongly typed • Based on type-safe metamodel of persistent classes and relationships • Heavy use of Java generics • Supports object-based or string-based navigation • Query construction at development time or runtime
  • 29. 29 Criteria API: Core Interfaces • CriteriaBuilder • Construct criteria queries, selections, predicates, orderings • CriteriaQuery • Used to add / replace/ browse query elements • from, select, where, orderBy, groupBy, having,… methods • Root • Query roots • Join, ListJoin, MapJoin, … • Joins from a root or existing join • Path • Navigation from a root, join, or path • Subquery
  • 30. 30 How to Build a Criteria Query EntityManager em = emf.createEntityManager(); CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery(Manufacturer.class); Root root = criteria.from(Manufacturer.class); // FROM clause criteria.select(root); // SELECT clause Predicate condition = builder.like(root.get(Manufacturer_.name), "%" + name + "%"); criteria.where(condition); // WHERE clause TypedQuery query = em.createQuery(criteria); // FIRE query List manufacturers = query.getResultList();
  • 31. 31 Validation New in JPA 2.0 • Leverages work of Bean Validation (JSR 303) • Automatic validation upon lifecycle events • PrePersist • PreUpdate • PreRemove • Validation-mode element in “persistence.xml” • AUTO, CALLBACK, NONE • NetBeans 7.0 M2 generates the constraints
  • 32. 32 Concurrency • Java Persistence assumes optimistic concurrency • Short-term read locks • Long-term write locks • Provider can defer writing to database to transaction commit • Application can flush to database on demand • Optimistic “locking” done via version attributes • Integral or timestamp attributes, managed by provider • Provider validates version when writing to database • Explicit lock() calls available to validate read data
  • 33. 33 Pessimistic Locking New in JPA 2.0 • Java Persistence assumes optimistic concurrency • Normal pessimistic locking • Persistent state of entity • Relationships, Element collections • Grab database locks upfront • JPA spec defines semantics, not mechanism • Provider can lock more (not less) • Lock modes • PESSIMISTIC_READ – grab shared lock • PESSIMISTIC_WRITE – grab exclusive lock • PESSIMISTIC_FORCE_INCREMENT – update version
  • 34. 34 Locking APIs • EntityManager methods: lock, find, refresh • Query / TypedQuery methods: setLockMode, setHint • NamedQuery annotation: lockMode element • javax.persistence.lock.scope property • javax.persistence.lock.timeout hint • PessimisticLockException (if transaction rolls back) • LockTimeoutException (if only statement rolls back)
  • 35. 35 Caching Configuration New in JPA 2.0 • EntityManager persistence context corresponds to “first level” cache • Entities managed by persistence provider • Entities read from database • Entities to be written to database • Most implementations also use second-level caches • Not always transparent to application • JPA 2.0 standardizes basic second-level cache options
  • 36. 36 Standard Configuration Properties • javax.persistence.jdbc.driver • javax.persistence.jdbc.url • javax.persistence.jdbc.user • javax.persistence.jdbc.password • . . .
  • 37. 37 Summary of JPA 2.0 New Features • More flexible modeling capabilities • Expanded O/R mapping functionality • Additions to Java Persistence query language • Criteria API • Metamodel API • Pessimistic locking • Support for validation • Standardization of many configuration options
  • 38. <Insert Picture Here> Using the Latest Java Persistence API 2.0 Features Arun Gupta, Java EE & GlassFish Guy blogs.sun.com/arungupta, @arungupta