SlideShare a Scribd company logo
1 of 50
Download to read offline
<Insert Picture Here>




JavaTM Persistence API 2.0: An Overview
Sanjeeb Sahoo
Sr. Staff Engineer, Sun, an Oracle Company
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.


                                                    2
JavaTM Persistence API: Brief History


• Java Persistence 1.0
  – Standardized object/relational mapping for Java
    applications
  – Available as part Java EE 5 Platform or standalone
  – Covered most of the essential features
• Java Persistence 2.0
  –   More and better      increased application portability
  –   Released in December 2009
  –   Available as part of Java EE 6 Platform or standalone
  –   Reference Implementation is EclipseLink
  –   Available as part of GlassFish v3



                                                               3
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




                                                                4
Packaging



• Java SE (Standalone Java Application)
  – Jar file with entities, application classes and META-
    INF/persistence.xml
• Java EE
  – War file
     • WEB-INF/classes/META-INF/persistence.xml
     • WEB-INF/lib/entities.jar (with META-INF/persistence.xml)
  – EJB jar
     • EJBs and entities and META-INF/persistence.xml
  – EAR file
     • lib/entities.jar with META-INF/persistence.xml



                                                                  5
Bootstrapping



• Java SE (Standalone Java Application)
  – Persistence.createEntityManagerFactory
• Java EE
  – @PersistenceContext EntityManager em;
  – @PersistenceUnit EntityManagerFactory emf;




                                                 6
JavaTM Persistence 2.0:
New Features

•   Expanded modeling capabilities
•   Additional O/R mapping options
•   Additions to Java Persistence query language
•   Metamodel API
•   Criteria API
•   Pessimistic locking
•   Standardization of many configuration options
•   Support for validation




                                                    7
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)


                                                                       8
JavaTM Persistence 2.0:
 Expanded modeling and mapping

• Collections of basic types
• Collections of embeddables
• Richer support for embeddable classes
  – Multiple levels of embedding
  – Embeddable classes with relationships
• Persistently ordered lists
• Improved map support
  – Joins with additional columns
  – Ternary relationships
• Orphan deletion


                                            9
JavaTM Persistence 2.0:
 Expanded modeling and mapping

• Derived identities
  – Improved modeling for overlapping primary and foreign
    keys
• Combinations of access types
• Expanded relationship mapping options
  – Unidirectional one-many foreign key mappings
  – One-one, many-one/one-many join table mappings




                                                            10
Collections of Basic Types and Embeddables


• Collections of strings, integers, etc.
• Collections of embeddables (e.g., Address, Detail)

• Specified by @ElementCollection
• Stored in “collection table”
• Customize mappings with:
  – @CollectionTable
  – @Column (for basic types)
  – @AttributeOverride, @AssociationOverride (for
    embeddables)



                                                       11
Collections of Basic Types


@Entity
public class Person {
    @Id protected String ssn;
    protected String name;
    protected Date birthDate;
    ...
    @ElementCollection
    protected Set<String> nickNames;
    ...
}




                                       12
Collections of Basic Types




   PERSON
   SSN   NAME    BIRTHDATE




                 PERSON_NICKNAMES
                 PERSON_SSN   NICKNAMES




                                          13
Collections of Embeddable Types


@Entity public class Landlord {
    @Id String taxId;
    String name;
    @ElementCollection
    @CollectionTable(name=“rentals”)
    Set<Address> properties;
    ...
}

@Embeddable public class Address {
    String street;
    String city;
    String state;
    ...
}




                                       14
Collections of Embeddable Types




  LANDLORD
  TAXID   NAME       …




           RENTALS
          LANDLORD_TAXID   STREET   CITY   STATE   …




                                                       15
Multiple Levels of Embedding



@Entity public class Employee {
      @Id int empId;
      String name;
      ContactInfo contactInfo;
      . . .
  }

@Embeddable public class ContactInfo {
      @Embedded Address address;
      . . .
  }




                                         16
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;
      . . .
  }




                                         17
Persistently Ordered Lists


• Order is maintained in database by provider
  – Uses additional (integral) ordering column
• Specified with @OrderColumn
• Provides alternative to @OrderBy




                                                 18
Persistently Ordered Lists


@Entity public class CreditCard {
   @Id String cardNumber;
   @ManyToOne Customer customer;
   ...
   @OneToMany(mappedBy=“creditCard”)
   @OrderColumn(name=“TXORDER”)
   List<CardTransaction> transactionHistory;
   ...
}

@Entity public class CardTransaction {
    @Id @GeneratedValue Long id;
    @ManyToOne @JoinColumn(name=“CARDID”)
    CreditCard creditCard;
    @Temporal(DATE) Date txDate;
    ...
}



                                               19
OrderColumn




 CREDITCARD
 CARDNUMBER   …




              CARDTRANSACTION
              CARDID   ID   TXDATE   …   TXORDER




                                                   20
@OrderBy Alternative


@Entity public class CreditCard {
   @Id String cardNumber;
   @ManyToOne Customer customer;
   ...
   @OneToMany(mappedBy=“creditCard”)
   @OrderColumn(name=“TXORDER”) @OrderBy(“txDate”)
   List<CardTransaction> transactionHistory;
   ...
}

@Entity public class CardTransaction {
    @Id @GeneratedValue Long id;
    @ManyToOne @JoinColumn(name=“CARDID”)
    CreditCard creditCard;
    @Temporal(DATE) Date txDate;
    ...
}



                                                     21
Generalized Maps


• Map key can be
  – Basic type
  – Embeddable
  – Entity
• Map value can be
  – Basic type
  – Embeddable
  – Entity
• Support for legacy join tables with additional
  columns
• Support for ternary relationships


                                                   22
Generalized Maps


• Map collection is specified with
  – @ElementCollection, @OneToMany, @ManyToMany
  – Annotation is determined by map value
• Customize mapping with:
  –   @CollectionTable (for element collection)
  –   @JoinTable (for relationship)
  –   @MapKeyColumn (for basic map key)
  –   @MapKeyJoinColumn(s) (for entity key)
  –   @AttributeOverride(s) using “key.” or “value.” syntax
      (for embeddables)




                                                              23
Generalized Maps


@Entity
public class VideoStore {
   @Id Integer storeId;
   Address location;
   @ElementCollection
   @CollectionTable(
         joinColumn=@JoinColumn(name=“VIDEO_STOREID”))
   Map<Movie, Integer> inventory;
   ...
}

@Entity
public class Movie {
   @Id String title;
   String director;
   ...
}



                                                         24
Generalized Maps




  VIDEOSTORE
  STOREID   NAME    STREET   CITY   STATE   …



                     MOVIE
                     TITLE   DIRECTOR       …



    VIDEOSTORE_INVENTORY
    VIDEO_STOREID    INVENTORY_KEY    INVENTORY




                                                  25
Automatic Orphan Deletion


• Deletion of related entities when removed from
  relationship
  – For entities logically “owned” by “parent”
  – For one-to-one and one-to-many relationships
• Specified with orphanRemoval element
  – cascade=REMOVE is redundant




                                                   26
Orphan Deletion


@Entity
public class Order {
   @Id int orderId;
   ...
   @OneToMany(cascade=PERSIST, orphanRemoval=true)
   Set<Item> items;
}




                                                     27
Java Persistence Query Language:
New Functionality

• Support for all new modeling and mapping
  features
• Operators and functions in select list
• Case, coalesce, nullif expressions
• Restricted polymorphism
• Collection-valued input parameters
• Date / time / timestamp literals




                                             28
New Operators


• INDEX
  – For ordered lists
• KEY, VALUE, ENTRY
  – For maps
• CASE, COALESCE, NULLIF
  – For case expressions and the like
• TYPE
  – For entity type expressions / restricted polymorphism




                                                            29
Restricted Polymorphism,
Collection-valued Input Parameters

SELECT e
FROM Employee e
WHERE TYPE(e) IN (PartTime, Contractor)


SELECT e
FROM Employee e
WHERE TYPE(e) IN :empTypes




                                          30
Criteria API


• Object-based API for building queries
• Designed to mirror JPQL semantics
• Strongly typed
  – Based on type-safe metamodel of persistence unit
  – Heavy use of Java generics
  – Typing carries through to query execution as well
• Supports object-based or strong-based navigation




                                                        31
Criteria API: Core Interfaces


• CriteriaQuery
  – Represents a query definition object
  – Used to add / replace / browse constituent query elements
  – select, from, where, orderBy, groupBy, having,… methods
• CriteriaBuilder
  – Factory for CriteriaQuery objects
  – Obtained from EntityManager or EntityManagerFactory
  – Used to create selections, expressions, restrictions,
    orderings…
• Root
  – Query root



                                                                32
Criteria API: Core Interfaces


• Join, ListJoin, MapJoin,…
  – Joins from a root or existing join
• Path
  – Navigation from a root, join, path
• Subquery
• Parameter
• TypedQuery
  – Executable query object
  – Extends Query interface
• Tuple
  – Multiple-valued result type


                                         33
The World’s Simplest Query


  SELECT c
  FROM Customer c


  CriteriaBuilder cb = ...;
  CriteriaQuery<Customer> cq = cb.createQuery(Customer.class);
  Root<Customer> c = cq.from(Customer.class);

  cq.select(c);




                                                                 34
Joins and Navigation


  SELECT c
  FROM Customer c join c.orders o


  CriteriaBuilder cb = ...;
  CriteriaQuery<Customer> cq   = cb.createQuery(Customer.class);
  Root<Customer> c = cq.from(Customer.class);
  Join<Customer, Order> o = customer.join(“orders”);
  cq.select(c);




                                                                   35
Joins and Navigation: What’s the Problem?


  SELECT c
  FROM Customer c join c.orders o


  CriteriaBuilder cb = ...;
  CriteriaQuery<Customer> cq   = cb.createQuery(Customer.class);
  Root<Customer> c = cq.from(Customer.class);
  Join<Customer, Order> o = customer.join(“wombats”);
  cq.select(c);




                                                                   36
Metamodel


• Abstract, “schema-level” view of managed
  classes of persistence unit
  – Entities, mapped superclasses, embeddables, and their
    attributes and relationships
• Accessible at runtime
  – EntityManagerFactory.getMetamodel()
  – EntityManager.getMetamodel()
• Useful for frameworks
• Provides foundation for type-safe queries
• Can be materialized as static metamodel classes
  – Use javac + annotation processor


                                                            37
Type-safe Navigation


  SELECT c
  FROM Customer c join c.orders o


  CriteriaBuilder cb = ...;
  CriteriaQuery<Customer> cq   = cb.createQuery(Customer.class);
  Root<Customer> c = cq.from(Customer.class);
  Join<Customer, Order> o = customer.join(Customer_.orders);
  cq.select(c);




                                                                   38
Optimistic Locking


• Assumes read-committed isolation, deferred
  writes
  – Short term read-locks
  – Long term write-locks
• Layered on top of @Version use
  – Verify version for updated entities before transaction
    commit
• Lock Modes
  – OPTIMISTIC (READ)
  – OPTIMISTIC_FORCE_INCREMENT (WRITE)
• “READ” lock => verify version for clean data
• “WRITE” lock => update version for clean data
                                                             39
Pessimistic Locking


• Grab database locks upfront
• Lock Modes
  – PESSIMISTIC_READ
  – PESSIMISTIC_WRITE
  – PESSIMISTIC_FORCE_INCREMENT
• Normal (default) pessimistic locking
  – Persistent state of entity (except element collections)
  – Relationships where entity holds foreign key
• Extended pessimistic locking
  – Uses javax.persistence.lock.scope property (EXTENDED)
  – Element collections and relationships in join tables
  – Phantoms are possible

                                                              40
Pessimistic Locking


@Stateless public class HRBean {
   ...
   @PersistenceContext EntityManager em;
   ...
   public void giveRaises(int deptId) {
       Department dept =
              em.find(Department.class, deptId,
                      LockModeType.PESSIMISTIC_READ);
       if (dept.getBudget() > 100000) {
         Query q = em.createQuery(
                       “SELECT emp ” +
                       “FROM Employee emp ” +
                       “WHERE emp.dept.id = ” + deptId);
         q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
         List = q.getResultList();
         // update employee salaries selectively...
       }
   }
}


                                                           41
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)
                                                   42
Second Level Cache APIs


• APIs and control options added for portability
• Cache interface methods: evict, evictAll, contains
• @Cacheable + shared-cache-mode XML element
  – ALL, NONE, ENABLE_SELECTIVE, DISABLE_SELECTIVE
• Properties for find, refresh, setProperty methods
  – javax.persistence.cache.retrieveMode property
     • USE, BYPASS
  – javax.persistence.cache.storeMode property
     • USE, BYPASS, REFRESH




                                                       43
Validation


• Leverages work of Bean Validation JSR (JSR 303)
• Automatic validation upon lifecycle events
  – PrePersist
  – PreUpdate
  – PreRemove
• persistence.xml validation-mode element
  – AUTO
  – CALLBACK
  – NONE




                                                    44
Validation


@Entity public class Employee {
    @Id Integer empId;
    @NotNull String name;
    Float salary;
    @Max(15) Integer vacationDays;
    @Valid Address worksite;
    ...
}

@Embeddable public class Address {
    @Size(max=30) String street;
    @Size(max=20) String city;
    @Size(min=2,max=2) String state;
    @Zipcode String zipcode;
    ...
}




                                       45
Standard Configuration Properties



•   javax.persistence.jdbc.driver
•   javax.persistence.jdbc.url
•   javax.persistence.jdbc.user
•   javax.persistence.jdbc.password
•   ...




                                        46
JPA 2.1 Candidate Features
    http://jcp.org/en/jsr/detail?id=338
                                             NEW

     Multi-tenancy

     Support for stored procedures, vendor function

     Update and Delete Criteria queries, JPQL ↔
     Criteria

     Query by Example

     Support for schema generation

     UUID generator type

     Persistence Context synchronization control

     Dynamic definition of PU

     Additional event listeners
                                                      47
Summary


•   Expanded modeling capabilities
•   Additional O/R mapping options
•   Additions to Java Persistence query language
•   Metamodel API
•   Criteria API
•   Pessimistic locking
•   Standardization of many configuration options
•   Support for validation
•   Improved portability



                                                    48
Resources


• Java Persistence 2.0 Specification
   http://jcp.org/en/jsr/detail?id=317
• Reference Implementation is EclipseLink
   http://www.eclipse.org/eclipselink
• Available as part of Java EE 6 with GlassFish
   http://glassfish.org
• Book: Pro JPA 2 (Keith & Schincariol)




                                                  49
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.


                                                    50

More Related Content

What's hot (20)

JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
 
JPA 2.0
JPA 2.0JPA 2.0
JPA 2.0
 
Java beans
Java beansJava beans
Java beans
 
Hibernate complete Training
Hibernate complete TrainingHibernate complete Training
Hibernate complete Training
 
Hibernate using jpa
Hibernate using jpaHibernate using jpa
Hibernate using jpa
 
Spark IT 2011 - Context & Dependency Injection in the Java EE 6 Ecosystem
Spark IT 2011 - Context & Dependency Injection in the Java EE 6 EcosystemSpark IT 2011 - Context & Dependency Injection in the Java EE 6 Ecosystem
Spark IT 2011 - Context & Dependency Injection in the Java EE 6 Ecosystem
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
JPA Best Practices
JPA Best PracticesJPA Best Practices
JPA Best Practices
 
Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPA
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
 
Intro To Hibernate
Intro To HibernateIntro To Hibernate
Intro To Hibernate
 
S313937 cdi dochez
S313937 cdi dochezS313937 cdi dochez
S313937 cdi dochez
 
JPA For Beginner's
JPA For Beginner'sJPA For Beginner's
JPA For Beginner's
 
Javabean1
Javabean1Javabean1
Javabean1
 
CDI @javaonehyderabad
CDI @javaonehyderabadCDI @javaonehyderabad
CDI @javaonehyderabad
 
Deployment
DeploymentDeployment
Deployment
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 

Similar to Java Persistence API 2.0: An Overview

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 IndiaArun Gupta
 
Using the latest Java Persistence API 2.0 features
Using the latest Java Persistence API 2.0 featuresUsing the latest Java Persistence API 2.0 features
Using the latest Java Persistence API 2.0 featuresArun Gupta
 
Understanding
Understanding Understanding
Understanding Arun Gupta
 
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
 
Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8Nicolas Thon
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/HibernateSunghyouk Bae
 
springdatajpa-up.pdf
springdatajpa-up.pdfspringdatajpa-up.pdf
springdatajpa-up.pdfssuser0562f1
 
FIWARE Global Summit - FIWARE Context Information Management
FIWARE Global Summit - FIWARE Context Information ManagementFIWARE Global Summit - FIWARE Context Information Management
FIWARE Global Summit - FIWARE Context Information ManagementFIWARE
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreIMC Institute
 
NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020Thodoris Bais
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)Samnang Chhun
 
Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpaStaples
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your CodeDrupalDay
 
Drupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comDrupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comJD Leonard
 

Similar to Java Persistence API 2.0: An Overview (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
 
Using the latest Java Persistence API 2.0 features
Using the latest Java Persistence API 2.0 featuresUsing the latest Java Persistence API 2.0 features
Using the latest Java Persistence API 2.0 features
 
Understanding
Understanding Understanding
Understanding
 
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)
 
ORM JPA
ORM JPAORM JPA
ORM JPA
 
Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8Nhibernatethe Orm For Net Platform 1226744632929962 8
Nhibernatethe Orm For Net Platform 1226744632929962 8
 
NHibernate
NHibernateNHibernate
NHibernate
 
Alternatives of JPA/Hibernate
Alternatives of JPA/HibernateAlternatives of JPA/Hibernate
Alternatives of JPA/Hibernate
 
Introduction to Datastore
Introduction to DatastoreIntroduction to Datastore
Introduction to Datastore
 
springdatajpa-up.pdf
springdatajpa-up.pdfspringdatajpa-up.pdf
springdatajpa-up.pdf
 
FIWARE Global Summit - FIWARE Context Information Management
FIWARE Global Summit - FIWARE Context Information ManagementFIWARE Global Summit - FIWARE Context Information Management
FIWARE Global Summit - FIWARE Context Information Management
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : Datastore
 
NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020
 
NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)NHibernate (The ORM For .NET Platform)
NHibernate (The ORM For .NET Platform)
 
Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpa
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Spring data
Spring dataSpring data
Spring data
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Drupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comDrupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.com
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 

Java Persistence API 2.0: An Overview

  • 1. <Insert Picture Here> JavaTM Persistence API 2.0: An Overview Sanjeeb Sahoo Sr. Staff Engineer, Sun, an Oracle Company
  • 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. 2
  • 3. JavaTM Persistence API: Brief History • Java Persistence 1.0 – Standardized object/relational mapping for Java applications – Available as part Java EE 5 Platform or standalone – Covered most of the essential features • Java Persistence 2.0 – More and better increased application portability – Released in December 2009 – Available as part of Java EE 6 Platform or standalone – Reference Implementation is EclipseLink – Available as part of GlassFish v3 3
  • 4. 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 4
  • 5. Packaging • Java SE (Standalone Java Application) – Jar file with entities, application classes and META- INF/persistence.xml • Java EE – War file • WEB-INF/classes/META-INF/persistence.xml • WEB-INF/lib/entities.jar (with META-INF/persistence.xml) – EJB jar • EJBs and entities and META-INF/persistence.xml – EAR file • lib/entities.jar with META-INF/persistence.xml 5
  • 6. Bootstrapping • Java SE (Standalone Java Application) – Persistence.createEntityManagerFactory • Java EE – @PersistenceContext EntityManager em; – @PersistenceUnit EntityManagerFactory emf; 6
  • 7. JavaTM Persistence 2.0: New Features • Expanded modeling capabilities • Additional O/R mapping options • Additions to Java Persistence query language • Metamodel API • Criteria API • Pessimistic locking • Standardization of many configuration options • Support for validation 7
  • 8. 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) 8
  • 9. JavaTM Persistence 2.0: Expanded modeling and mapping • Collections of basic types • Collections of embeddables • Richer support for embeddable classes – Multiple levels of embedding – Embeddable classes with relationships • Persistently ordered lists • Improved map support – Joins with additional columns – Ternary relationships • Orphan deletion 9
  • 10. JavaTM Persistence 2.0: Expanded modeling and mapping • Derived identities – Improved modeling for overlapping primary and foreign keys • Combinations of access types • Expanded relationship mapping options – Unidirectional one-many foreign key mappings – One-one, many-one/one-many join table mappings 10
  • 11. Collections of Basic Types and Embeddables • Collections of strings, integers, etc. • Collections of embeddables (e.g., Address, Detail) • Specified by @ElementCollection • Stored in “collection table” • Customize mappings with: – @CollectionTable – @Column (for basic types) – @AttributeOverride, @AssociationOverride (for embeddables) 11
  • 12. Collections of Basic Types @Entity public class Person { @Id protected String ssn; protected String name; protected Date birthDate; ... @ElementCollection protected Set<String> nickNames; ... } 12
  • 13. Collections of Basic Types PERSON SSN NAME BIRTHDATE PERSON_NICKNAMES PERSON_SSN NICKNAMES 13
  • 14. Collections of Embeddable Types @Entity public class Landlord { @Id String taxId; String name; @ElementCollection @CollectionTable(name=“rentals”) Set<Address> properties; ... } @Embeddable public class Address { String street; String city; String state; ... } 14
  • 15. Collections of Embeddable Types LANDLORD TAXID NAME … RENTALS LANDLORD_TAXID STREET CITY STATE … 15
  • 16. Multiple Levels of Embedding @Entity public class Employee { @Id int empId; String name; ContactInfo contactInfo; . . . } @Embeddable public class ContactInfo { @Embedded Address address; . . . } 16
  • 17. 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; . . . } 17
  • 18. Persistently Ordered Lists • Order is maintained in database by provider – Uses additional (integral) ordering column • Specified with @OrderColumn • Provides alternative to @OrderBy 18
  • 19. Persistently Ordered Lists @Entity public class CreditCard { @Id String cardNumber; @ManyToOne Customer customer; ... @OneToMany(mappedBy=“creditCard”) @OrderColumn(name=“TXORDER”) List<CardTransaction> transactionHistory; ... } @Entity public class CardTransaction { @Id @GeneratedValue Long id; @ManyToOne @JoinColumn(name=“CARDID”) CreditCard creditCard; @Temporal(DATE) Date txDate; ... } 19
  • 20. OrderColumn CREDITCARD CARDNUMBER … CARDTRANSACTION CARDID ID TXDATE … TXORDER 20
  • 21. @OrderBy Alternative @Entity public class CreditCard { @Id String cardNumber; @ManyToOne Customer customer; ... @OneToMany(mappedBy=“creditCard”) @OrderColumn(name=“TXORDER”) @OrderBy(“txDate”) List<CardTransaction> transactionHistory; ... } @Entity public class CardTransaction { @Id @GeneratedValue Long id; @ManyToOne @JoinColumn(name=“CARDID”) CreditCard creditCard; @Temporal(DATE) Date txDate; ... } 21
  • 22. Generalized Maps • Map key can be – Basic type – Embeddable – Entity • Map value can be – Basic type – Embeddable – Entity • Support for legacy join tables with additional columns • Support for ternary relationships 22
  • 23. Generalized Maps • Map collection is specified with – @ElementCollection, @OneToMany, @ManyToMany – Annotation is determined by map value • Customize mapping with: – @CollectionTable (for element collection) – @JoinTable (for relationship) – @MapKeyColumn (for basic map key) – @MapKeyJoinColumn(s) (for entity key) – @AttributeOverride(s) using “key.” or “value.” syntax (for embeddables) 23
  • 24. Generalized Maps @Entity public class VideoStore { @Id Integer storeId; Address location; @ElementCollection @CollectionTable( joinColumn=@JoinColumn(name=“VIDEO_STOREID”)) Map<Movie, Integer> inventory; ... } @Entity public class Movie { @Id String title; String director; ... } 24
  • 25. Generalized Maps VIDEOSTORE STOREID NAME STREET CITY STATE … MOVIE TITLE DIRECTOR … VIDEOSTORE_INVENTORY VIDEO_STOREID INVENTORY_KEY INVENTORY 25
  • 26. Automatic Orphan Deletion • Deletion of related entities when removed from relationship – For entities logically “owned” by “parent” – For one-to-one and one-to-many relationships • Specified with orphanRemoval element – cascade=REMOVE is redundant 26
  • 27. Orphan Deletion @Entity public class Order { @Id int orderId; ... @OneToMany(cascade=PERSIST, orphanRemoval=true) Set<Item> items; } 27
  • 28. Java Persistence Query Language: New Functionality • Support for all new modeling and mapping features • Operators and functions in select list • Case, coalesce, nullif expressions • Restricted polymorphism • Collection-valued input parameters • Date / time / timestamp literals 28
  • 29. New Operators • INDEX – For ordered lists • KEY, VALUE, ENTRY – For maps • CASE, COALESCE, NULLIF – For case expressions and the like • TYPE – For entity type expressions / restricted polymorphism 29
  • 30. Restricted Polymorphism, Collection-valued Input Parameters SELECT e FROM Employee e WHERE TYPE(e) IN (PartTime, Contractor) SELECT e FROM Employee e WHERE TYPE(e) IN :empTypes 30
  • 31. Criteria API • Object-based API for building queries • Designed to mirror JPQL semantics • Strongly typed – Based on type-safe metamodel of persistence unit – Heavy use of Java generics – Typing carries through to query execution as well • Supports object-based or strong-based navigation 31
  • 32. Criteria API: Core Interfaces • CriteriaQuery – Represents a query definition object – Used to add / replace / browse constituent query elements – select, from, where, orderBy, groupBy, having,… methods • CriteriaBuilder – Factory for CriteriaQuery objects – Obtained from EntityManager or EntityManagerFactory – Used to create selections, expressions, restrictions, orderings… • Root – Query root 32
  • 33. Criteria API: Core Interfaces • Join, ListJoin, MapJoin,… – Joins from a root or existing join • Path – Navigation from a root, join, path • Subquery • Parameter • TypedQuery – Executable query object – Extends Query interface • Tuple – Multiple-valued result type 33
  • 34. The World’s Simplest Query SELECT c FROM Customer c CriteriaBuilder cb = ...; CriteriaQuery<Customer> cq = cb.createQuery(Customer.class); Root<Customer> c = cq.from(Customer.class); cq.select(c); 34
  • 35. Joins and Navigation SELECT c FROM Customer c join c.orders o CriteriaBuilder cb = ...; CriteriaQuery<Customer> cq = cb.createQuery(Customer.class); Root<Customer> c = cq.from(Customer.class); Join<Customer, Order> o = customer.join(“orders”); cq.select(c); 35
  • 36. Joins and Navigation: What’s the Problem? SELECT c FROM Customer c join c.orders o CriteriaBuilder cb = ...; CriteriaQuery<Customer> cq = cb.createQuery(Customer.class); Root<Customer> c = cq.from(Customer.class); Join<Customer, Order> o = customer.join(“wombats”); cq.select(c); 36
  • 37. Metamodel • Abstract, “schema-level” view of managed classes of persistence unit – Entities, mapped superclasses, embeddables, and their attributes and relationships • Accessible at runtime – EntityManagerFactory.getMetamodel() – EntityManager.getMetamodel() • Useful for frameworks • Provides foundation for type-safe queries • Can be materialized as static metamodel classes – Use javac + annotation processor 37
  • 38. Type-safe Navigation SELECT c FROM Customer c join c.orders o CriteriaBuilder cb = ...; CriteriaQuery<Customer> cq = cb.createQuery(Customer.class); Root<Customer> c = cq.from(Customer.class); Join<Customer, Order> o = customer.join(Customer_.orders); cq.select(c); 38
  • 39. Optimistic Locking • Assumes read-committed isolation, deferred writes – Short term read-locks – Long term write-locks • Layered on top of @Version use – Verify version for updated entities before transaction commit • Lock Modes – OPTIMISTIC (READ) – OPTIMISTIC_FORCE_INCREMENT (WRITE) • “READ” lock => verify version for clean data • “WRITE” lock => update version for clean data 39
  • 40. Pessimistic Locking • Grab database locks upfront • Lock Modes – PESSIMISTIC_READ – PESSIMISTIC_WRITE – PESSIMISTIC_FORCE_INCREMENT • Normal (default) pessimistic locking – Persistent state of entity (except element collections) – Relationships where entity holds foreign key • Extended pessimistic locking – Uses javax.persistence.lock.scope property (EXTENDED) – Element collections and relationships in join tables – Phantoms are possible 40
  • 41. Pessimistic Locking @Stateless public class HRBean { ... @PersistenceContext EntityManager em; ... public void giveRaises(int deptId) { Department dept = em.find(Department.class, deptId, LockModeType.PESSIMISTIC_READ); if (dept.getBudget() > 100000) { Query q = em.createQuery( “SELECT emp ” + “FROM Employee emp ” + “WHERE emp.dept.id = ” + deptId); q.setLockMode(LockModeType.PESSIMISTIC_WRITE); List = q.getResultList(); // update employee salaries selectively... } } } 41
  • 42. 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) 42
  • 43. Second Level Cache APIs • APIs and control options added for portability • Cache interface methods: evict, evictAll, contains • @Cacheable + shared-cache-mode XML element – ALL, NONE, ENABLE_SELECTIVE, DISABLE_SELECTIVE • Properties for find, refresh, setProperty methods – javax.persistence.cache.retrieveMode property • USE, BYPASS – javax.persistence.cache.storeMode property • USE, BYPASS, REFRESH 43
  • 44. Validation • Leverages work of Bean Validation JSR (JSR 303) • Automatic validation upon lifecycle events – PrePersist – PreUpdate – PreRemove • persistence.xml validation-mode element – AUTO – CALLBACK – NONE 44
  • 45. Validation @Entity public class Employee { @Id Integer empId; @NotNull String name; Float salary; @Max(15) Integer vacationDays; @Valid Address worksite; ... } @Embeddable public class Address { @Size(max=30) String street; @Size(max=20) String city; @Size(min=2,max=2) String state; @Zipcode String zipcode; ... } 45
  • 46. Standard Configuration Properties • javax.persistence.jdbc.driver • javax.persistence.jdbc.url • javax.persistence.jdbc.user • javax.persistence.jdbc.password • ... 46
  • 47. JPA 2.1 Candidate Features http://jcp.org/en/jsr/detail?id=338 NEW  Multi-tenancy  Support for stored procedures, vendor function  Update and Delete Criteria queries, JPQL ↔ Criteria  Query by Example  Support for schema generation  UUID generator type  Persistence Context synchronization control  Dynamic definition of PU  Additional event listeners 47
  • 48. Summary • Expanded modeling capabilities • Additional O/R mapping options • Additions to Java Persistence query language • Metamodel API • Criteria API • Pessimistic locking • Standardization of many configuration options • Support for validation • Improved portability 48
  • 49. Resources • Java Persistence 2.0 Specification http://jcp.org/en/jsr/detail?id=317 • Reference Implementation is EclipseLink http://www.eclipse.org/eclipselink • Available as part of Java EE 6 with GlassFish http://glassfish.org • Book: Pro JPA 2 (Keith & Schincariol) 49
  • 50. 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. 50