• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
The Evolution of Java Persistence
 

The Evolution of Java Persistence

on

  • 1,362 views

Slides from my talk at Devoxx 2012 on the innovations that are taking place in the EclipseLink project.

Slides from my talk at Devoxx 2012 on the innovations that are taking place in the EclipseLink project.

Statistics

Views

Total Views
1,362
Views on SlideShare
1,225
Embed Views
137

Actions

Likes
5
Downloads
0
Comments
2

2 Embeds 137

https://twitter.com 136
https://si0.twimg.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

12 of 2 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • LOL. Obviously there is another Java persistence standard, but Oracle like to 'forget' it. Haha. You guys are so funny
    Are you sure you want to
    Your message goes here
    Processing…
  • This was a great talk, but why aren't the slides downloadable?
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • -The “mappedBy” concept used by MOXy follows the “mappedBy” concept used by JPA.
  • -The “mappedBy” concept used by MOXy follows the “mappedBy” concept used by JPA.
  • You have to write Beans that provide access to entities via methods that are mapped with JAX-RS to URIs.
  • 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)

The Evolution of Java Persistence The Evolution of Java Persistence Presentation Transcript

  • 1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • The Evolution of JavaPersistenceShaun Smith@shaunMsmith2 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 Relational4 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 – NoSQL5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • EclipseLink Project Java SE Java EE OSGi JPA MOXy DBWS Databases XML Data Legacy Systems6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • JSON Binding7 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/Unmarshaller8 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 JSON10 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 Weaving11 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 ProjectEmployee Project project project Marshall Unmarshall13 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 Unmarshall15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Demo JAXB/JPA Fidelity JSON Binding16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Dynamic JPA17 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 support18 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@VirtualAccessMethodspublic class Player{…@Transientprivate 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);}PLAYERID F_NAME L_NAME FLEX_1 FLEX_21 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-RS23 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/430 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 db31 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 JPA32 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 JPA33 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 ... JPA34 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 applications35 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Demo EclipseLink JPA-RS36 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • NoSQL Java Persistence37 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 databases38 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 Entity42 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 NoSQL44 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…well 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 ThoughtWorks45 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • Demo Polyglot Persistence46 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 MOXy47 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 persistence48 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 49 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.