SlideShare a Scribd company logo
„JPA 2.0“
New Features of JSR 317
JSR 317: Java Persistence API
• Specification Lead:
  Linda DeMichiel, Sun Microsystems, Inc.
• Expert Group:
  Adobe Systems Inc., akquinet tech@spree, BEA Systems, Adam Bien,
  DataDirect Technologies, Ericsson AB, Antonio Goncalves, IBM, Chris Maki,
  Oracle, OW2, Pramati Technologies, RedHat, SAP AG Sun Microsystems
  Inc., Sybase, TmaxSoft Inc., VMWare
• Referenzimplemention:
  EclipseLink 2.x, www.eclipse.org/eclipselink




                                                                              1
Goals
• Expanded O/R mappings
• Improved domain modeling capabilities
• Additions to the Java Persistence query language
• An API for criteria queries
• Standardization of configuration hints
• Additional contracts for detached entities and extended persistence
  contexts
• Support for validation via integration with the work of JSR 303




                                                                        2
@OneToMany / @ManyToOne
 @OneToMany
 @JoinColumn(name = "ID")
 private List<Editor> editors;




markus@eisele.net                3
@ElementCollection

 @ElementCollection
 private Set<String> websites = new HashSet();




markus@eisele.net                                4
@OrderColumn

 @OrderColumn(name="ED_ORDER")
 private List<Editor> editors;




markus@eisele.net                5
@MapKeyJoinColumn
 @JoinTable(name="ADRESSESS",
          joinColumns=
          @JoinColumn(name="AUTORID"),
          inverseJoinColumns=@JoinColumn(name="CONTACTID"))
 @MapKeyJoinColumn(name="ADRESSID")
 Map<Adress, Contactdetails> allAdressess;




markus@eisele.net                                             6
@Embeddable
 @Embedded
 PhoneNumber number;

 @ManyToOne
 PhoneServiceProvider provider;




markus@eisele.net                 7
@Access
@Entity @Access(FIELD)
public class PhoneNumber {
...
@Transient String localnumber;

@Access(PROPERTY)
protected double getInternationalNumber(Locale locale) {
return convertToIntNumber(localnumber);
}
...
}




                                                           8
Combined Primary Keys
 @Entity
 @IdClass(ArticlePK.class)
 public class Article {

 @Id Long id;
 @Id @ManyToOne Magazine magazine;
 @Id @ManyToOne Author author;
 }

 public class ArticlePK {
        Long id;
        Long magazine;
        Long author;
 }




markus@eisele.net                    9
Criteria API I
 // create / inject EntityManager
 EntityManager em = ...;

 // build Criteria Query
 CriteriaBuilder qb = em.getCriteriaBuilder();
 CriteriaQuery cq = qb.createQuery();
 Root<Author> autor = cq.from(Author.class);
 cq.select(author);

 // execute Criteria Query
 Query query = em.createQuery(cq);
 List result = query.getResultList();




markus@eisele.net                                10
Criteria API II
Root autor = cq.from(Author.class);
cq.where(qb.equal(author.get("name"), name));
cq.select(autor);




markus@eisele.net                               11
Metamodel API
@Entity public class Customer {
  @Id int custId;
  String name;
  ...
  @OneToMany(mappedBy="customer") Set<Order> orders;
  ...
}



import javax.persistence.metamodel.*;
@TypesafeMetamodel
public class Customer_ {
    public static volatile Attribute<Customer, Integer> custId;
    public static volatile Attribute<Customer, String> name;
    public static volatile Set<Customer, Order> orders;
    ...
}




                                                                  12
Metamodel API + Criteria API

cq.where(qb.equal(autor.get(Autor_.name), "name"));




markus@eisele.net                                     13
Bean Validation (JSR-303)
@Entity
public class Autor implements Serializable {
[…]
@NotNull
@Size(max=30)
private String name;
[…]
}


 •@NotNull
 •@Size.max
 •@Digits
 •@Min / @Max
 •@Future / @Past
 •@Size


markus@eisele.net                              14
LockModeTypes
.READ => LockModeType.OPTIMISTIC
.WRITE => LockModeType.OPTIMISTIC_FORCE_INCREMENT

NEW!:
LockModeType.PESSIMISTIC_READ (Repeatable Read)
LockModeType.PESSIMISTIC_WRITE (Serialized)
LockModeType.PESSIMISTIC_FORCE_INCREMENT




 markus@eisele.net                                  15
JPQL Enhancements
•   Timestamp
•   Non-polymorphic Queries
•   Collection Paramters in IN Expression
•   Ordered List Index
•   CASE Statement




                                            16
Second Level Cache

public interface Cache {
boolean contains(Class clz, Object primaryKey);
void evict(Class clz, Object primaryKey);
void evict(Class clz);
void evictAll();
}




 markus@eisele.net                                17
Links und Informationen
•   http://blog.eisele.net/
•   http://blogs.sun.com/ldemichiel/
•   http://www.jcp.org/en/jsr/detail?id=317
•   http://www.eclipse.org/eclipselink




markus@eisele.net                             18

More Related Content

PPTX
Dependency injection - the right way
PDF
Intro to Core Data
PDF
Rabin Shrestha: Data Validation and Sanitization in WordPress
PDF
Distributing information on iOS
PPTX
Hibernate working with criteria- Basic Introduction
PPTX
Test Data Builder Pattern
PDF
Dependency Injection with Unity Container
PDF
Filtering data with D2W
Dependency injection - the right way
Intro to Core Data
Rabin Shrestha: Data Validation and Sanitization in WordPress
Distributing information on iOS
Hibernate working with criteria- Basic Introduction
Test Data Builder Pattern
Dependency Injection with Unity Container
Filtering data with D2W

What's hot (19)

PPTX
Creating data with the test data builder pattern
PPTX
Inversion of Control and Dependency Injection
PPTX
Dependency Injection Inversion Of Control And Unity
PDF
iOS State Preservation and Restoration
PDF
Drupal 7 Entity & Entity API
PPT
ODP
Consume Spring Data Rest with Angularjs
PPTX
Using MongoDB with the .Net Framework
PDF
Spring 3: What's New
PDF
Cassandra rapid prototyping with achilles
PPTX
Entity framework 6
ODP
Hibernate complete Training
KEY
Intro to IndexedDB (Beta)
PDF
Vaadin JPAContainer
PPT
Entity Persistence with JPA
ODP
JPA Best Practices
PDF
Java persistence api 2.1
ODP
Codebits 2012 - Fast relational web site construction.
Creating data with the test data builder pattern
Inversion of Control and Dependency Injection
Dependency Injection Inversion Of Control And Unity
iOS State Preservation and Restoration
Drupal 7 Entity & Entity API
Consume Spring Data Rest with Angularjs
Using MongoDB with the .Net Framework
Spring 3: What's New
Cassandra rapid prototyping with achilles
Entity framework 6
Hibernate complete Training
Intro to IndexedDB (Beta)
Vaadin JPAContainer
Entity Persistence with JPA
JPA Best Practices
Java persistence api 2.1
Codebits 2012 - Fast relational web site construction.
Ad

Viewers also liked (20)

PDF
PDF
Hibernate - JPA @luce 5
PDF
Introducción práctica a JPA2
PDF
Introduction to JPA and Hibernate including examples
PDF
Pdf Pai
PDF
Quantum Entanglement - Cryptography and Communication
PPTX
The silent way
PDF
Shero Company profile,2016
PPTX
BSidesNYC 2016 - An Adversarial View of SaaS Malware Sandboxes
PPTX
2016.10.28 Transistor 2 - engelsk tekst - sven age eriksen v.05 - Sven Åge ...
DOCX
FOOD ANYWHERE IS FOOD EVERYWHERE
PDF
iNut Limited Leather Beani Tablet Range
PDF
осъдителна присъда кюстендилски окръжен съд
PPT
Strategic Management Ch05
PPT
Building A Social Network Waa 1 17 07 V2 Draft
PDF
Zhao_Work samples
PPT
Step Up 1 and 2 ppt
PDF
Zenoss Monitroing – zendmd Scripting Guide
PDF
dfasdfsdf
Hibernate - JPA @luce 5
Introducción práctica a JPA2
Introduction to JPA and Hibernate including examples
Pdf Pai
Quantum Entanglement - Cryptography and Communication
The silent way
Shero Company profile,2016
BSidesNYC 2016 - An Adversarial View of SaaS Malware Sandboxes
2016.10.28 Transistor 2 - engelsk tekst - sven age eriksen v.05 - Sven Åge ...
FOOD ANYWHERE IS FOOD EVERYWHERE
iNut Limited Leather Beani Tablet Range
осъдителна присъда кюстендилски окръжен съд
Strategic Management Ch05
Building A Social Network Waa 1 17 07 V2 Draft
Zhao_Work samples
Step Up 1 and 2 ppt
Zenoss Monitroing – zendmd Scripting Guide
dfasdfsdf
Ad

Similar to New Features of JSR 317 (JPA 2.0) (20)

PDF
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
PDF
Understanding
PDF
Using the latest Java Persistence API 2.0 features
PDF
S313431 JPA 2.0 Overview
PDF
Java Persistence 2.0
PDF
PDF
Java Persistence API 2.0: An Overview
KEY
Enterprise Java Web Application Frameworks Sample Stack Implementation
ODP
Working with jpa
PDF
Whats New In Java Ee 6
PDF
Appengine Java Night #2a
PPTX
PDF
Orcale Presentation
PDF
Data access 2.0? Please welcome: Spring Data!
PDF
JPA - Java Persistence API
PDF
appengine java night #1
PPTX
Codecamp iasi-26 nov 2011-what's new in jpa 2.0
PPT
Spring data
DOC
Hibernate Online Training
PPTX
Jpa queries
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
Understanding
Using the latest Java Persistence API 2.0 features
S313431 JPA 2.0 Overview
Java Persistence 2.0
Java Persistence API 2.0: An Overview
Enterprise Java Web Application Frameworks Sample Stack Implementation
Working with jpa
Whats New In Java Ee 6
Appengine Java Night #2a
Orcale Presentation
Data access 2.0? Please welcome: Spring Data!
JPA - Java Persistence API
appengine java night #1
Codecamp iasi-26 nov 2011-what's new in jpa 2.0
Spring data
Hibernate Online Training
Jpa queries

More from Markus Eisele (20)

PDF
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
PDF
Backstage Software Templates for Java Developers
PDF
SparksCon 2024 - Die Ringe der Macht
PDF
Sustainable Software Architecture - Open Tour DACH '22
PDF
Going from java message service (jms) to eda
PDF
Let's be real. Quarkus in the wild.
PDF
What happens when unicorns drink coffee
PDF
Stateful on Stateless - The Future of Applications in the Cloud
PDF
Java in the age of containers - JUG Frankfurt/M
PDF
Java in the Age of Containers and Serverless
PDF
Migrating from Java EE to cloud-native Reactive systems
PDF
Streaming to a new Jakarta EE / JOTB19
PDF
Cloud wars - A LavaOne discussion in seven slides
PDF
Streaming to a new Jakarta EE
PDF
Reactive Integrations - Caveats and bumps in the road explained
PDF
Stay productive while slicing up the monolith
PDF
Stay productive while slicing up the monolith
PDF
Stay productive_while_slicing_up_the_monolith
PDF
Architecting for failure - Why are distributed systems hard?
PDF
Stay productive while slicing up the monolith
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Backstage Software Templates for Java Developers
SparksCon 2024 - Die Ringe der Macht
Sustainable Software Architecture - Open Tour DACH '22
Going from java message service (jms) to eda
Let's be real. Quarkus in the wild.
What happens when unicorns drink coffee
Stateful on Stateless - The Future of Applications in the Cloud
Java in the age of containers - JUG Frankfurt/M
Java in the Age of Containers and Serverless
Migrating from Java EE to cloud-native Reactive systems
Streaming to a new Jakarta EE / JOTB19
Cloud wars - A LavaOne discussion in seven slides
Streaming to a new Jakarta EE
Reactive Integrations - Caveats and bumps in the road explained
Stay productive while slicing up the monolith
Stay productive while slicing up the monolith
Stay productive_while_slicing_up_the_monolith
Architecting for failure - Why are distributed systems hard?
Stay productive while slicing up the monolith

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Big Data Technologies - Introduction.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf
20250228 LYD VKU AI Blended-Learning.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Big Data Technologies - Introduction.pptx
sap open course for s4hana steps from ECC to s4
Diabetes mellitus diagnosis method based random forest with bat algorithm
The Rise and Fall of 3GPP – Time for a Sabbatical?
Review of recent advances in non-invasive hemoglobin estimation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation_ Review paper, used for researhc scholars
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
MIND Revenue Release Quarter 2 2025 Press Release
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Advanced methodologies resolving dimensionality complications for autism neur...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Approach and Philosophy of On baking technology

New Features of JSR 317 (JPA 2.0)

  • 2. JSR 317: Java Persistence API • Specification Lead: Linda DeMichiel, Sun Microsystems, Inc. • Expert Group: Adobe Systems Inc., akquinet tech@spree, BEA Systems, Adam Bien, DataDirect Technologies, Ericsson AB, Antonio Goncalves, IBM, Chris Maki, Oracle, OW2, Pramati Technologies, RedHat, SAP AG Sun Microsystems Inc., Sybase, TmaxSoft Inc., VMWare • Referenzimplemention: EclipseLink 2.x, www.eclipse.org/eclipselink 1
  • 3. Goals • Expanded O/R mappings • Improved domain modeling capabilities • Additions to the Java Persistence query language • An API for criteria queries • Standardization of configuration hints • Additional contracts for detached entities and extended persistence contexts • Support for validation via integration with the work of JSR 303 2
  • 4. @OneToMany / @ManyToOne @OneToMany @JoinColumn(name = "ID") private List<Editor> editors; markus@eisele.net 3
  • 5. @ElementCollection @ElementCollection private Set<String> websites = new HashSet(); markus@eisele.net 4
  • 6. @OrderColumn @OrderColumn(name="ED_ORDER") private List<Editor> editors; markus@eisele.net 5
  • 7. @MapKeyJoinColumn @JoinTable(name="ADRESSESS", joinColumns= @JoinColumn(name="AUTORID"), inverseJoinColumns=@JoinColumn(name="CONTACTID")) @MapKeyJoinColumn(name="ADRESSID") Map<Adress, Contactdetails> allAdressess; markus@eisele.net 6
  • 8. @Embeddable @Embedded PhoneNumber number; @ManyToOne PhoneServiceProvider provider; markus@eisele.net 7
  • 9. @Access @Entity @Access(FIELD) public class PhoneNumber { ... @Transient String localnumber; @Access(PROPERTY) protected double getInternationalNumber(Locale locale) { return convertToIntNumber(localnumber); } ... } 8
  • 10. Combined Primary Keys @Entity @IdClass(ArticlePK.class) public class Article { @Id Long id; @Id @ManyToOne Magazine magazine; @Id @ManyToOne Author author; } public class ArticlePK { Long id; Long magazine; Long author; } markus@eisele.net 9
  • 11. Criteria API I // create / inject EntityManager EntityManager em = ...; // build Criteria Query CriteriaBuilder qb = em.getCriteriaBuilder(); CriteriaQuery cq = qb.createQuery(); Root<Author> autor = cq.from(Author.class); cq.select(author); // execute Criteria Query Query query = em.createQuery(cq); List result = query.getResultList(); markus@eisele.net 10
  • 12. Criteria API II Root autor = cq.from(Author.class); cq.where(qb.equal(author.get("name"), name)); cq.select(autor); markus@eisele.net 11
  • 13. Metamodel API @Entity public class Customer { @Id int custId; String name; ... @OneToMany(mappedBy="customer") Set<Order> orders; ... } import javax.persistence.metamodel.*; @TypesafeMetamodel public class Customer_ { public static volatile Attribute<Customer, Integer> custId; public static volatile Attribute<Customer, String> name; public static volatile Set<Customer, Order> orders; ... } 12
  • 14. Metamodel API + Criteria API cq.where(qb.equal(autor.get(Autor_.name), "name")); markus@eisele.net 13
  • 15. Bean Validation (JSR-303) @Entity public class Autor implements Serializable { […] @NotNull @Size(max=30) private String name; […] } •@NotNull •@Size.max •@Digits •@Min / @Max •@Future / @Past •@Size markus@eisele.net 14
  • 16. LockModeTypes .READ => LockModeType.OPTIMISTIC .WRITE => LockModeType.OPTIMISTIC_FORCE_INCREMENT NEW!: LockModeType.PESSIMISTIC_READ (Repeatable Read) LockModeType.PESSIMISTIC_WRITE (Serialized) LockModeType.PESSIMISTIC_FORCE_INCREMENT markus@eisele.net 15
  • 17. JPQL Enhancements • Timestamp • Non-polymorphic Queries • Collection Paramters in IN Expression • Ordered List Index • CASE Statement 16
  • 18. Second Level Cache public interface Cache { boolean contains(Class clz, Object primaryKey); void evict(Class clz, Object primaryKey); void evict(Class clz); void evictAll(); } markus@eisele.net 17
  • 19. Links und Informationen • http://blog.eisele.net/ • http://blogs.sun.com/ldemichiel/ • http://www.jcp.org/en/jsr/detail?id=317 • http://www.eclipse.org/eclipselink markus@eisele.net 18