1   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
The Evolution of Java
Persistence

Shaun Smith
@shaunMsmith



2   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
The following 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   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Persistence: The Problem Space
                                   Customer                                                <customer id=―…‖>
                                                                                              <name>…</name>
                           id: int                                         JAXB               …
                           name: String                                                    </contact-info>
                           creditRating: int                                               </customer>
                                              Java
                                                                                                   XML
                                               JPA
                                                                           DBWS



                            CUST
                                                                                  JPA: Java Persistence API
                      ID NAME C_RATING                                            JAXB: Java Architecture for XML Binding
                                  Relational

4   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Persistence
           Standards: JPA 2.0, JAXB 2.2,                                   Tomorrow
            SDO 2.1.1
                                                                               JPA 2.1
           Recent
                    – JSON Binding
                                                                               JSON-B
                    – Dynamic JPA                                              Java Standard for
                    – Tenant Isolation                                         NoSQL Persistence?
                    – RESTful JPA
                    – NoSQL




5   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
EclipseLink Project

               Java SE                                                     Java EE          OSGi


                                 JPA                                       MOXy      DBWS




                                Databases                           XML Data         Legacy Systems


6   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JSON Binding




7   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JSON Binding / EclipseLink ―JSON-B‖

           Provides Java/JSON binding similar to EclipseLink JAXB‘s Java/XML
            binding.
           Marshall Java domain model to and from JSON
           Currently no Java standard—EclipseLink interprets JAXB XML
            bindings for JSON
           Content-type selectable by setting property on
            Marshaller/Unmarshaller




8   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
EclipseLink JSON-B Goals

           Offer the same flexibility as object-to-XML mappings
           Support both XML and JSON with one set of mappings
           No additional compile time dependencies over the JAXB APIs
           Be easy to use with JAX-RS (i.e., MessageBodyReader and
               MessageBodyWriter)




9   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
XML and JSON from JAXB Mappings


                                                                            XML




                      JAXB mapped Java
                                                                            JSON




10   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Challenges – Mapping JPA Entities to XML

<?xml version="1.0" ?>
<employee>
  <first>Mark</first>
  <last>Twain</last>
  <id>1</id>                                              JAXB              JPA
</employee>


                      • Bidirectional/Cyclical Relationships
                      • Composite Keys/Embedded Key Classes
                      • Byte Code Weaving




11   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Bidirectional Relationship
                      @Entity
                      public class Project{
                         ...
                         @OneToMany(mappedBy=“project")
                         private List<Employee> members;
                      }
                      @Entity
                      public class Employee{
                         ...
                         @ManyToOne
                         private Project project;
                      }




12   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Bidirectional Relationships in JAXB

            JAXB specification does not support bidirectional relationships. One
                side must be marked @XmlTransient.
            But that loses the relationship!

                                                                                 <?xml version="1.0" ?>
                                                                                 <employee>
                                                                                   <first>Mark</first>
                                              members                              <last>Twain</last>
                                                                                   <id>1</id>                                  X
                                                                                 </employee>                  Employee             Project
Employee                                                     Project

            project                                                                                                  project
                                                                            Marshall             Unmarshall

13   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
EclipseLink XmlInverseReference
                      @Entity
                      public class Project{
                        ...
                        @OneToMany(mappedBy=“project")
                        private List<Employee> members;
                      }
                      @Entity
                      public class Employee{
                        ...
                        @ManyToOne
                        @XmlInverseReference(mappedBy=“members")
                        private Project project;
                      }
14   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
EclipseLink XmlInverseReference

            EclipseLink restores relationships on unmarshall!

                                                       members                                                                 members


      Employee                                                       Project       <?xml version="1.0" ?>
                                                                                                              Employee              Project
                                                                                   <employee>
                                                                                     <first>Mark</first>
                                                                                     <last>Twain</last>
                     project                                                         <id>1</id>                      project
                                                                                   </employee>
                                                                        Marshall                        Unmarshall




15   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Demo
                                                                                JAXB/JPA Fidelity
                                                                                JSON Binding




16   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Dynamic JPA




17   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Dynamic JPA
         Post development flexibility

            JPA entities without .java or .class
                     – Entity definitions defined through eclipselink-orm.xml
                     – VIRTUAL entities and attribute access
                     – Entity classes created on the fly (ASM)
            Extensible entity types
                     – Define additional attributes to static entities
                     – Values stored in Map
                     – Full query and metamodel support




18   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Dynamic Entity
<entity class="model.Address" access="VIRTUAL">
   <attributes>
      <id name="addressId" attribute-type="int">
          <column name="ADDRESS_ID" />
      </id>
      <basic name="city" attribute-type="String” />
      <basic name="country" attribute-type="String” />
      <basic name="pCode" attribute-type="String” >
          <column name="P_CODE" />
      </basic>




19   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Extensible Entity Types

            Storage and querying of extended properties
                     – Application developer enables extensions in entity
                     – Schema created with extension columns/table(s)
                     – Application Admin stores extension definitions
                     – Application instances made aware of extension definitions
                     – Application users make use of extensions

                                         Employee
                                                id                          extensions            *   name
                                           firstName                                                  value
                                           lastName                         Map<String, Object>
20   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Extensions Configuration
@VirtualAccessMethods
public class Player{
…
@Transient
private Map<String, Object> attributes;

public <T> T get(String attributeName) {
        return (T) this.attributes.get(attributeName);
}
public Object set(String attributeName, Object value) {
         return this.attributes.put(attributeName, value);
}

PLAYER
ID                               F_NAME                               L_NAME   FLEX_1   FLEX_2
1                                John                                 Doe      ‗R‘      ‘22‘
2                                Jane                                 Smith    ‗NONE‘


21   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Virtual Access Mappings
<entity class="example.mysports.model.Player">
          <attributes>
                      <basic name="penaltyMinutes" access="VIRTUAL"
                                                  attribute-type="java.lang.Integer">
                                  <column name="flex_1"/>
                      </basic>
                      <basic name="position" access="VIRTUAL"
                                      attribute-type="java.lang.String">
                                  <column name="flex_2"/>
                      </basic>
          </attributes>
</entity>


22   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
RESTful JPA: JPA-RS




23   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
REST and JAX-RS

                   REST – REpresentational State Transfer
                    –         Addressable resources (URI per resource)
                    –         Small set of well-defined
                    –         Representation-oriented
                    –         Communicate statelessly
            JAX-RS (JSR 331 & in progress 339): Java API for RESTful Services
                     – Java EE framework for implementing RESTful services
                     – Provides annotations to bind combination of URI and HTTP operation to
                             Java methods.


24   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JAX-RS with JPA Example – GET Invoice


           public class InvoiceService {...




            public Invoice read(int id) {
               return null;
            }
           ...

25   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JAX-RS with JPA Example – GET Invoice

           @Stateless
           public class InvoiceService {...




            public Invoice read(int id) {
               return entityManager.find(Invoice.class, id);
            }
           ...

26   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JAX-RS with JPA Example – GET Invoice
           @Path("/invoice")
           @Stateless
           public class InvoiceService {...




            public Invoice read(int id) {
               return entityManager.find(Invoice.class, id);
            }
           ...

27   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JAX-RS with JPA Example – GET Invoice
           @Path("/invoice")
           @Stateless
           public class InvoiceService {...

            @GET
            @Path("{id}")
            public Invoice read(@PathParam("id") int id) {
               return entityManager.find(Invoice.class, id);
            }
           ...

28   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JAX-RS with JPA Example – GET Invoice
           @Path("/invoice")
           @Stateless
           public class InvoiceService {...
            @GET
            @Path("{id}")
            @Produces({"application/xml", "application/json"})
            public Invoice read(@PathParam("id") int id) {
               return entityManager.find(Invoice.class, id);
            }
           ...

29   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JAX-RS with JPA Example – GET Invoice
           @Path("/invoice")
           @Stateless
           public class InvoiceService {...
            @GET
            @Path("{id}")
            @Produces({"application/xml", "application/json"})
            public Invoice read(@PathParam("id") int id) {
               return entityManager.find(Invoice.class, id);
            }
           ...        GET http://[machine]:[port]/[web-context]/invoice/4

30   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JAX-RS with JPA—High Level Architecture
     Client                                                                 Java EE Server          RDBMS




                                           HTTP/S                                            JDBC




        Offline db

31   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JAX-RS with JPA Example
                                                                                 JAX-RS

                                                            Invoice Bean        Contract Bean      Payment Bean
                                                                                                                  Accounting
                                                                                                                  Application
                                                                            Accounting Persistence Unit




                                                                                    JPA




32   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JAX-RS with JPA                                                                  GET http://.../invoice/4
                       GET http://.../invoice/4
                       mapped to bean                                            JAX-RS

                                                            Invoice Bean        Contract Bean      Payment Bean
                                                                                                                  Accounting
                                                                                                                  Application
                                   Bean                                     Accounting Persistence Unit

                                   uses JPA




                                                                                    JPA




33   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
GET http://.../jpa-rs/Accounting/Invoice/...
         JPA-RS
                                                                              JAX-RS http://.../jpa-rs/Accounting/Invoice/...
                                                                               JAX-RS
                                                                              mapped to JPA-RS service
                                                                               JPA-RS
                                                                             JPA-RS maps URI http://.../jpa-
                                                                              rs/Accounting/Invoice/...
                                  Accounting PU                               to Accounting PU and Invoice entityPU
                                                                            Contracting PU          Human Resources

                                                                                                ...



                                                                                  JPA




34   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JPA-RS Features

            Access relational data through REST with JSON or XML
            Provides REST operations for entities in persistence unit (GET, PUT,
             POST, DELETE)
            Supports invocation of named queries via HTTP
            Server Caching—EclipseLink clustered cache
            Dynamic Persistence also supported
                     – Entities defined via metadata—no Java classes required
                     – Enables persistence services for HTML 5/JavaScript applications




35   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Demo EclipseLink JPA-RS




36   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
NoSQL Java Persistence




37   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
NoSQL Databases

            NoSQL database are increasingly popular
            No common definition (document, graph, columnar)
                     – Differing feature sets
                     – Some offer query language/API—some not
            No standards
            Every database offers a unique API
                     – Cost in terms of learning
                     – Zero portability across databases



38   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
EclipseLink NoSQL

            Support JPA-style access to NoSQL databases
                     – Leverage non-relational database support for JCA (and JDBC when
                             available)
            Define annotations and XML to identify NoSQL stored entities (e.g.,
             @NoSQL)
            Support JPQL subset for each
                     – Key principal: leverage what‘s available
            Initial support for MongoDB and Oracle NoSQL.
            Support mixing relational and non-relational data in single composite
                persistence unit (―polyglot persistence‖)
39   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Applicability of JPA to NoSQL

            Core JPA concepts apply to NoSQL:
                     – Persistent
                             Entities, Embeddables, ElementCollection, OneToOne, OneToMany, Many
                             ToOne, Version, etc.
            Some concepts apply with some databases:
                     – JPQL, NamedNativeQuery
            Pure relational concepts don‘t apply:
                     – CollectionTable, Column, SecondaryTable, SequenceGenerator, TableGen
                             erator, etc.


40   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Querying NoSQL with JPA

            Two kinds of queries
                     – JQPL—portable query language defined by the spec
                     – Native query—lets you leverage database specific features
                     – Dynamic or static @NamedQuery
            JPQL translated to underlying database query framework.




41   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Example MongoDB Mapped Entity




42   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
MongoDB Query Examples

            JPQL
                  Select o from Order o
                    where o.totalCost > 1000
                Select o from Order o
                  join o.orderLines l where l.cost > :cost

            Native Queries
                  query = em.createNativeQuery(
                    "db.ORDER.findOne({"_id":"" +
                    oid + ""})", Order.class);
                Order order =
                  (Order) query.getSingleResult();
43   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Demo EclipseLink NoSQL




44   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
―…we are gearing up for a shift to polyglot persistence - where any
          decent sized enterprise will have a variety of different data storage
          technologies for different kinds of data…we'll be first asking how
          we want to manipulate the data and only then figuring out what
          technology is the best bet for it..‖

            Martin Fowler
            ThoughtWorks




45   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Demo Polyglot Persistence




46   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Releases & Roadmap
                                 2010                                           2011                  2012                2013
                        EclipseLink 2.1                                     EclipseLink 2.3       EclipseLink 2.4      EclipseLink 2.5
                             Helios                                              Indigo                Juno                Kepler
                        • Query Extensions
                          • TREAT AS                                        • Tenant Isolation    • JSON Binding       • JPA 2.1
                          • FUNC                                              • SINGLE_TABLE      • JPA-RS             • …
                        • Batch IN and                                      • Extensible          • Tenant Isolation
                          EXISTS
                        • Attribute Group
                                                                            • External              • Tenant per
                          • Load                                              Metadata                Table/Schema
                          • Fetch                                           • Multiple DBs        • ALTER Schema
                          • Copy                                            • Data Partitioning
                          • Merge                                                                 • NoSQL
                        • eclispelink-
                          oxm.xml
                        • Dynamic MOXy




47   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Summary

            Java is evolving—and EclipseLink is evolving too!
                     – JSON Binding
                     – JAXB/JPA Fidelity
                     – Dynamic JPA
                     – JPA-RS
                     – NoSQL
                     – Polyglot Persistence
            EclipseLink is the center of innovation in Java persistence



48   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
49   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

The Evolution of Java Persistence

  • 1.
    1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 2.
    The Evolution ofJava Persistence Shaun Smith @shaunMsmith 2 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 3.
    The following isintended 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 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 4.
    Java Persistence: TheProblem Space Customer <customer id=―…‖> <name>…</name> id: int JAXB … name: String </contact-info> creditRating: int </customer> Java XML JPA DBWS CUST JPA: Java Persistence API ID NAME C_RATING JAXB: Java Architecture for XML Binding Relational 4 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 5.
    Java Persistence  Standards: JPA 2.0, JAXB 2.2,  Tomorrow SDO 2.1.1  JPA 2.1  Recent – JSON Binding  JSON-B – Dynamic JPA  Java Standard for – Tenant Isolation NoSQL Persistence? – RESTful JPA – NoSQL 5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 6.
    EclipseLink Project Java SE Java EE OSGi JPA MOXy DBWS Databases XML Data Legacy Systems 6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 7.
    JSON Binding 7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 8.
    JSON Binding /EclipseLink ―JSON-B‖  Provides Java/JSON binding similar to EclipseLink JAXB‘s Java/XML binding.  Marshall Java domain model to and from JSON  Currently no Java standard—EclipseLink interprets JAXB XML bindings for JSON  Content-type selectable by setting property on Marshaller/Unmarshaller 8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 9.
    EclipseLink JSON-B Goals  Offer the same flexibility as object-to-XML mappings  Support both XML and JSON with one set of mappings  No additional compile time dependencies over the JAXB APIs  Be easy to use with JAX-RS (i.e., MessageBodyReader and MessageBodyWriter) 9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 10.
    XML and JSONfrom JAXB Mappings XML JAXB mapped Java JSON 10 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 11.
    Challenges – MappingJPA Entities to XML <?xml version="1.0" ?> <employee> <first>Mark</first> <last>Twain</last> <id>1</id> JAXB JPA </employee> • Bidirectional/Cyclical Relationships • Composite Keys/Embedded Key Classes • Byte Code Weaving 11 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 12.
    Bidirectional Relationship @Entity public class Project{ ... @OneToMany(mappedBy=“project") private List<Employee> members; } @Entity public class Employee{ ... @ManyToOne private Project project; } 12 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 13.
    Bidirectional Relationships inJAXB  JAXB specification does not support bidirectional relationships. One side must be marked @XmlTransient.  But that loses the relationship! <?xml version="1.0" ?> <employee> <first>Mark</first> members <last>Twain</last> <id>1</id> X </employee> Employee Project Employee Project project project Marshall Unmarshall 13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 14.
    EclipseLink XmlInverseReference @Entity public class Project{ ... @OneToMany(mappedBy=“project") private List<Employee> members; } @Entity public class Employee{ ... @ManyToOne @XmlInverseReference(mappedBy=“members") private Project project; } 14 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 15.
    EclipseLink XmlInverseReference  EclipseLink restores relationships on unmarshall! members members Employee Project <?xml version="1.0" ?> Employee Project <employee> <first>Mark</first> <last>Twain</last> project <id>1</id> project </employee> Marshall Unmarshall 15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 16.
    Demo JAXB/JPA Fidelity JSON Binding 16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 17.
    Dynamic JPA 17 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 18.
    Dynamic JPA Post development flexibility  JPA entities without .java or .class – Entity definitions defined through eclipselink-orm.xml – VIRTUAL entities and attribute access – Entity classes created on the fly (ASM)  Extensible entity types – Define additional attributes to static entities – Values stored in Map – Full query and metamodel support 18 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 19.
    Dynamic Entity <entity class="model.Address"access="VIRTUAL"> <attributes> <id name="addressId" attribute-type="int"> <column name="ADDRESS_ID" /> </id> <basic name="city" attribute-type="String” /> <basic name="country" attribute-type="String” /> <basic name="pCode" attribute-type="String” > <column name="P_CODE" /> </basic> 19 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 20.
    Extensible Entity Types  Storage and querying of extended properties – Application developer enables extensions in entity – Schema created with extension columns/table(s) – Application Admin stores extension definitions – Application instances made aware of extension definitions – Application users make use of extensions Employee id extensions * name firstName value lastName Map<String, Object> 20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 21.
    Extensions Configuration @VirtualAccessMethods public classPlayer{ … @Transient private Map<String, Object> attributes; public <T> T get(String attributeName) { return (T) this.attributes.get(attributeName); } public Object set(String attributeName, Object value) { return this.attributes.put(attributeName, value); } PLAYER ID F_NAME L_NAME FLEX_1 FLEX_2 1 John Doe ‗R‘ ‘22‘ 2 Jane Smith ‗NONE‘ 21 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 22.
    Virtual Access Mappings <entityclass="example.mysports.model.Player"> <attributes> <basic name="penaltyMinutes" access="VIRTUAL" attribute-type="java.lang.Integer"> <column name="flex_1"/> </basic> <basic name="position" access="VIRTUAL" attribute-type="java.lang.String"> <column name="flex_2"/> </basic> </attributes> </entity> 22 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 23.
    RESTful JPA: JPA-RS 23 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 24.
    REST and JAX-RS  REST – REpresentational State Transfer – Addressable resources (URI per resource) – Small set of well-defined – Representation-oriented – Communicate statelessly  JAX-RS (JSR 331 & in progress 339): Java API for RESTful Services – Java EE framework for implementing RESTful services – Provides annotations to bind combination of URI and HTTP operation to Java methods. 24 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 25.
    JAX-RS with JPAExample – GET Invoice public class InvoiceService {... public Invoice read(int id) { return null; } ... 25 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 26.
    JAX-RS with JPAExample – GET Invoice @Stateless public class InvoiceService {... public Invoice read(int id) { return entityManager.find(Invoice.class, id); } ... 26 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 27.
    JAX-RS with JPAExample – GET Invoice @Path("/invoice") @Stateless public class InvoiceService {... public Invoice read(int id) { return entityManager.find(Invoice.class, id); } ... 27 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 28.
    JAX-RS with JPAExample – GET Invoice @Path("/invoice") @Stateless public class InvoiceService {... @GET @Path("{id}") public Invoice read(@PathParam("id") int id) { return entityManager.find(Invoice.class, id); } ... 28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 29.
    JAX-RS with JPAExample – GET Invoice @Path("/invoice") @Stateless public class InvoiceService {... @GET @Path("{id}") @Produces({"application/xml", "application/json"}) public Invoice read(@PathParam("id") int id) { return entityManager.find(Invoice.class, id); } ... 29 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 30.
    JAX-RS with JPAExample – GET Invoice @Path("/invoice") @Stateless public class InvoiceService {... @GET @Path("{id}") @Produces({"application/xml", "application/json"}) public Invoice read(@PathParam("id") int id) { return entityManager.find(Invoice.class, id); } ... GET http://[machine]:[port]/[web-context]/invoice/4 30 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 31.
    JAX-RS with JPA—HighLevel Architecture Client Java EE Server RDBMS HTTP/S JDBC Offline db 31 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 32.
    JAX-RS with JPAExample JAX-RS Invoice Bean Contract Bean Payment Bean Accounting Application Accounting Persistence Unit JPA 32 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 33.
    JAX-RS with JPA GET http://.../invoice/4 GET http://.../invoice/4 mapped to bean JAX-RS Invoice Bean Contract Bean Payment Bean Accounting Application Bean Accounting Persistence Unit uses JPA JPA 33 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 34.
    GET http://.../jpa-rs/Accounting/Invoice/... JPA-RS JAX-RS http://.../jpa-rs/Accounting/Invoice/... JAX-RS mapped to JPA-RS service JPA-RS JPA-RS maps URI http://.../jpa- rs/Accounting/Invoice/... Accounting PU to Accounting PU and Invoice entityPU Contracting PU Human Resources ... JPA 34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 35.
    JPA-RS Features  Access relational data through REST with JSON or XML  Provides REST operations for entities in persistence unit (GET, PUT, POST, DELETE)  Supports invocation of named queries via HTTP  Server Caching—EclipseLink clustered cache  Dynamic Persistence also supported – Entities defined via metadata—no Java classes required – Enables persistence services for HTML 5/JavaScript applications 35 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 36.
    Demo EclipseLink JPA-RS 36 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 37.
    NoSQL Java Persistence 37 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 38.
    NoSQL Databases  NoSQL database are increasingly popular  No common definition (document, graph, columnar) – Differing feature sets – Some offer query language/API—some not  No standards  Every database offers a unique API – Cost in terms of learning – Zero portability across databases 38 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 39.
    EclipseLink NoSQL  Support JPA-style access to NoSQL databases – Leverage non-relational database support for JCA (and JDBC when available)  Define annotations and XML to identify NoSQL stored entities (e.g., @NoSQL)  Support JPQL subset for each – Key principal: leverage what‘s available  Initial support for MongoDB and Oracle NoSQL.  Support mixing relational and non-relational data in single composite persistence unit (―polyglot persistence‖) 39 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 40.
    Applicability of JPAto NoSQL  Core JPA concepts apply to NoSQL: – Persistent Entities, Embeddables, ElementCollection, OneToOne, OneToMany, Many ToOne, Version, etc.  Some concepts apply with some databases: – JPQL, NamedNativeQuery  Pure relational concepts don‘t apply: – CollectionTable, Column, SecondaryTable, SequenceGenerator, TableGen erator, etc. 40 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 41.
    Querying NoSQL withJPA  Two kinds of queries – JQPL—portable query language defined by the spec – Native query—lets you leverage database specific features – Dynamic or static @NamedQuery  JPQL translated to underlying database query framework. 41 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 42.
    Example MongoDB MappedEntity 42 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 43.
    MongoDB Query Examples  JPQL Select o from Order o where o.totalCost > 1000 Select o from Order o join o.orderLines l where l.cost > :cost  Native Queries query = em.createNativeQuery( "db.ORDER.findOne({"_id":"" + oid + ""})", Order.class); Order order = (Order) query.getSingleResult(); 43 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 44.
    Demo EclipseLink NoSQL 44 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 45.
    ―…we are gearingup for a shift to polyglot persistence - where any decent sized enterprise will have a variety of different data storage technologies for different kinds of data…we'll be first asking how we want to manipulate the data and only then figuring out what technology is the best bet for it..‖ Martin Fowler ThoughtWorks 45 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 46.
    Demo Polyglot Persistence 46 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 47.
    Releases & Roadmap 2010 2011 2012 2013 EclipseLink 2.1 EclipseLink 2.3 EclipseLink 2.4 EclipseLink 2.5 Helios Indigo Juno Kepler • Query Extensions • TREAT AS • Tenant Isolation • JSON Binding • JPA 2.1 • FUNC • SINGLE_TABLE • JPA-RS • … • Batch IN and • Extensible • Tenant Isolation EXISTS • Attribute Group • External • Tenant per • Load Metadata Table/Schema • Fetch • Multiple DBs • ALTER Schema • Copy • Data Partitioning • Merge • NoSQL • eclispelink- oxm.xml • Dynamic MOXy 47 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 48.
    Summary  Java is evolving—and EclipseLink is evolving too! – JSON Binding – JAXB/JPA Fidelity – Dynamic JPA – JPA-RS – NoSQL – Polyglot Persistence  EclipseLink is the center of innovation in Java persistence 48 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 49.
    49 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Editor's Notes

  • #14 -The “mappedBy” concept used by MOXy follows the “mappedBy” concept used by JPA.
  • #16 -The “mappedBy” concept used by MOXy follows the “mappedBy” concept used by JPA.
  • #33 You have to write Beans that provide access to entities via methods that are mapped with JAX-RS to URIs.
  • #41 Apparent even within a singleapplicationCost of complexity has to be addressedhttp://www.nearinfinity.com/blogs/scott_leberknight/polyglot_persistence.htmlhttp://martinfowler.com/bliki/PolyglotPersistence.htmlNoSQL Distilled (Sadalage and Fowler, 2012)