SlideShare a Scribd company logo
Practical RESTful Persistence
with EclipseLink JPA-RS
Shaun Smith
Oracle

#DV13 #JPARS

@shaunMsmith
•
•
•
•

JPA 2.0 (EE 6) and 2.1 (EE 7) reference implementation
JPA provider in GlassFish and Oracle WebLogic
Project founded on mature Oracle TopLink codebase
EPL and EDL licensed open source JPA and JAXB
implementation

#DV13 #JPARS

@shaunMsmith
Browser

Database

#DV13 #JPARS

@shaunMsmith
Browser

Java

Database

#DV13 #JPARS

@shaunMsmith
Browser

Java
EclipseLink JPA
Database

#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS

Java
EclipseLink JPA
Database

#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS
EclipseLink JAXB / JSON Binding
Java
EclipseLink JPA
Database

#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS
EclipseLink MOXy
Java
EclipseLink JPA
Database

#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS
EclipseLink MOXy
Java
EclipseLink JPA
Database

#DV13 #JPARS

@shaunMsmith
Browser
Browser
HTML5

JAX-RS
EclipseLink MOXy
Java
EclipseLink JPA
Database

#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS
EclipseLink MOXy
{
id: 5,
…
}

Java
EclipseLink JPA
Database

#DV13 #JPARS

@shaunMsmith
Browser
{
id: 5,
…
}

JAX-RS
EclipseLink MOXy
Java
EclipseLink JPA
Database

#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS
EclipseLink MOXy
Java
EclipseLink JPA
Database

#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS
EclipseLink MOXy
Java
EclipseLink JPA
Database

#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS
Binding Persistence
EclipseLink MOXy
XML / JSON

Java
Java Persistence
EclipseLink JPA
Relational / NoSQL

Database

#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS
Binding Persistence
EclipseLink MOXy
XML / JSON

Java
Java Persistence
EclipseLink JPA
Relational / NoSQL

Database

#DV13 #JPARS

@shaunMsmith
EclipseLink MOXy
•
•
•

JAXB for Java/XML binding—covert Java to/from XML
Java/JSON binding—convert Java to/from JSON
Currently no Java/JSON binding standard

• Java API for JSON Processing (JSR 535) is parsing, not binding
• EclipseLink interprets JAXB XML bindings for JSON
• Content-type selectable by setting property on
Marshaller/Unmarshaller

#DV13 #JPARS

@shaunMsmith
XML and JSON from JAXB Mappings

{
"phone-numbers" : [ {
"id" : 2,
"num" : "512-555-9999",
"type" : "mobile"
} ],
"address" : {
"city" : "New York",
"id" : 1,
"street" : "Central Park East"
},
"firstName" : "Woody",
"id" : 1,
"lastName" : “Allen"

<?xml version="1.0" encoding="UTF-8"?>
<customer>
<phone-numbers>
<phone-number>
<id>2</id>
<num>512-555-1234</num>
<type>home</type>
</phone-number>
</phone-numbers>
<address>
<city>New York</city>
<id>1</id>
<street>Central Park East</street>
</address>
<firstName>Bill</firstName>
<id>1</id>
<lastName>Allen</lastName>
</customer>

}

#DV13 #JPARS

@shaunMsmith
Challenges – Binding JPA Entities to
XML/JSON
<customer>
<phone-numbers>
<phone-number>
<id>1</id>
...
<type>mobile</type>
</phone-number>
</phone-numbers>
</customer>

•
•
•

JAXB

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

#DV13 #JPARS

JPA

@shaunMsmith
Bidirectional Relationship
@Entity
public class Customer{
...
@OneToMany(mappedBy="owner")
private List<Phone> phones;
}
@Entity
public class Phone{
...
@ManyToOne
private Customer owner;
}

#DV13 #JPARS

@shaunMsmith
What about @XmlTransient?
@Entity
public class Customer{
...
@OneToMany(mappedBy=“owner")
private List<Phone> phones;
}
@Entity
public class Phone{
...
@ManyToOne
@XmlTransient
private Customer owner;
}

#DV13 #JPARS

@shaunMsmith
With @XmlTransient
Loses the relationship!

owner

Customer
phones

#DV13 #JPARS

Phone

<customer>
<phone-numbers>
<phone-number>
<id>1</id>
...
<type>mobile</type>
</phone-number>
</phone-numbers>
</customer>

Marshall
Marshall

X

Customer

Unmarshall
Unmarshall

Phone

phones

@shaunMsmith
EclipseLink XmlInverseReference
@Entity
public class Customer{
...
@OneToMany(mappedBy=“owner")
private List<Phone> phones;
}
@Entity
public class Phone{
...
@ManyToOne
@XmlInverseReference(mappedBy=“phones")
private Customer owner;
}

#DV13 #JPARS

@shaunMsmith
With @XmlInverseReference
EclipseLink restores relationships on unmarshall!

owner

Customer
phones

#DV13 #JPARS

Phone

<customer>
<phone-numbers>
<phone-number>
<id>1</id>
...
<type>mobile</type>
</phone-number>
</phone-numbers>
</customer>

Marshall
Marshall

owner

Customer

Unmarshall
Unmarshall

Phone

phones

@shaunMsmith
Demo
#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS
JAX-RS
Binding Persistence
EclipseLink MOXy
XML / JSON

Java
Java Persistence
EclipseLink JPA
Relational / NoSQL

Database

#DV13 #JPARS

@shaunMsmith
JAX-RS with JPA Example
public class InvoiceService {...

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

@shaunMsmith
JAX-RS with JPA Example
@Stateless
public class InvoiceService {...

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

@shaunMsmith
JAX-RS with JPA Example
@Path("/invoice")
@Stateless
public class InvoiceService {...

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

http://[machine]:[port]/[web-context]/invoice
http://[machine]:[port]/[web-context]/invoice
@shaunMsmith
JAX-RS with JPA Example
@Path("/invoice")
@Stateless
public class InvoiceService {...

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

http://[machine]:[port]/[web-context]/invoice/4
http://[machine]:[port]/[web-context]/invoice/4
@shaunMsmith
JAX-RS with JPA Example
@Path("/invoice")
@Stateless
public class InvoiceService {...
@GET
@Path("{id}”)
public Invoice read(int id) {
return entityManager.find(Invoice.class, id);
}
...
#DV13 #JPARS

GET http://[machine]:[port]/[web-context]/invoice/4
GET http://[machine]:[port]/[web-context]/invoice/4
@shaunMsmith
JAX-RS with JPA Example
@Path("/invoice")
@Stateless
public class InvoiceService {...
@Produces({"application/xml"})
@GET
@Path("{id}")
public Invoice read(@PathParam("id") int id) {
return entityManager.find(Invoice.class, id);
}
...
#DV13 #JPARS

GET http://[machine]:[port]/[web-context]/invoice/4
GET http://[machine]:[port]/[web-context]/invoice/4
@shaunMsmith
JAX-RS with JPA

GET http://.../invoice/4
GET http://.../invoice/4
http://.../invoice/4 mapped to
http://.../invoice/4 mapped to
JAX-RS
JAX-RS
beanGET http://.../invoice/4 mapped to method
beanGET http://.../invoice/4 mapped to method

Invoice Bean
GET
GET
GET
GET
GET
GET
GET
GET

Bean uses JPA
Bean uses JPA

Contract Bean
GET
GET
GET
GET
GET
GET

Payment Bean
GET
GET
GET
GET
GET
GET

...

Accounting PU

JPA

#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS
JAX-RS
EclipseLink MOXy
EclipseLink MOXy
Java
Java
EclipseLink JPA
EclipseLink JPA
JPA-RS
JPA-RS
Database

#DV13 #JPARS

@shaunMsmith
EclipseLink JPA-RS
•

Automatically provides REST operations for entities in
persistence unit (GET, PUT, POST, DELETE)

•

Automatic generation of XML and JSON bindings
• Leverages EclipseLink’s JAXB/JPA fidelity features to avoid lossy
transformations

•

Automatic publication of REST API metadata

#DV13 #JPARS

@shaunMsmith
EclipseLink JPA-RS
•

Supports invocation of named queries via HTTP

•

Server side caching—EclipseLink clustered cache

•

Automatic injection of links for entity relationships
• Default Resource Model generation

#DV13 #JPARS

@shaunMsmith
{

"id": 2,
"city": ”Toronto",
…
}

...

Browser

"id": 1,
"lastName": "Smith",
…
"address": {
"_link": {
"href": "http:/…/Address/2",
"method": "GET",
"rel": "self"
}
}

{

1
1

2
2
...

Java

Database
#DV13 #JPARS

@shaunMsmith
Configuring JPA-RS
•

Add JPA-RS web fragment jar to WEB-INF/lib!

#DV13 #JPARS

@shaunMsmith
JPA-RS

GET http://.../persistence/Accounting/Invoice/4
GET http://.../persistence/Accounting/Invoice/4
JAX-RS http://.../persistence/Accounting/Invoice/4
JAX-RS http://.../persistence/Accounting/Invoice/4
JAX-RS
JAX-RS
mapped to JPA-RS service
mapped to JPA-RS service

Accounting

JPA-RS
JPA-RS maps URI
JPA-RS maps URI
http://.../persistence/Accounting/Invoice/4 to
http://.../persistence/Accounting/Invoice/4 to
Human Resources
Accounting PU and Invoice entity
Accounting PU and Invoice Benefits
entity
...

JPA

#DV13 #JPARS

@shaunMsmith
Demo
#DV13 #JPARS

@shaunMsmith
Demo Model

#DV13 #JPARS

@shaunMsmith
EclipseLink JPA-RS Roadmap
•

Resource Model

• Scope of resource
• Entity format
• partial entities/projections
• Configuration
• URL mapping/customization
• Manage Entity exposure
• Meta-data
• JSON Schema? Swagger? ...
#DV13 #JPARS

@shaunMsmith
Browser
JAX-RS
EclipseLink MOXy
Java
EclipseLink JPA
Database

#DV13 #JPARS

@shaunMsmith
Summary
•
•
•

Java EE stack has (most of) what you need to build Thin Server
Architecture applications
You have to be aware of various impedance mismatches
EclipseLink JPA-RS
• Integrates JAX-RS / JAXB / JPA
• Eliminates JAX-RS boilerplate for data access
• Simplifies Java EE Thin Server Architecture applications

☛ www.eclipse.org/eclipselink
#DV13 #JPARS

@shaunMsmith
The 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.

#DV13 #JPARS

@shaunMsmith

More Related Content

PPTX
The Evolution of Java Persistence
PDF
IBM Solutions '99 XML and Java: Lessons Learned
PDF
JAX-RS 2.0: RESTful Web Services
PDF
Java EE 7 overview
PDF
Java EE 7 - Overview and Status
PDF
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
PDF
Websocket 1.0
PDF
Java EE 7 and HTML5: Developing for the Cloud
The Evolution of Java Persistence
IBM Solutions '99 XML and Java: Lessons Learned
JAX-RS 2.0: RESTful Web Services
Java EE 7 overview
Java EE 7 - Overview and Status
JAX-RS 2.0: New and Noteworthy in RESTful Web services API at JAX London
Websocket 1.0
Java EE 7 and HTML5: Developing for the Cloud

What's hot (19)

PDF
JAX-RS 2.0: What’s New in JSR 339 ?
PPT
Java EE 7 (Hamed Hatami)
PPTX
Move from J2EE to Java EE
PDF
SD Forum 1999 XML Lessons Learned
PDF
Java EE Revisits GoF Design Patterns
PPTX
JSON-B for CZJUG
PDF
What's coming in Java EE 8
PDF
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
PDF
Java Web Programming [3/9] : Servlet Advanced
PDF
JSONB introduction and comparison with other frameworks
PPT
Java EE Introduction
PDF
Java Web Programming [4/9] : JSP Basic
PDF
PPT
Have You Seen Java EE Lately?
PDF
Sharding using MySQL and PHP
PDF
15 expression-language
PDF
JSP Standard Tag Library
PPTX
What's new in the Java API for JSON Binding
PDF
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
JAX-RS 2.0: What’s New in JSR 339 ?
Java EE 7 (Hamed Hatami)
Move from J2EE to Java EE
SD Forum 1999 XML Lessons Learned
Java EE Revisits GoF Design Patterns
JSON-B for CZJUG
What's coming in Java EE 8
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
Java Web Programming [3/9] : Servlet Advanced
JSONB introduction and comparison with other frameworks
Java EE Introduction
Java Web Programming [4/9] : JSP Basic
Have You Seen Java EE Lately?
Sharding using MySQL and PHP
15 expression-language
JSP Standard Tag Library
What's new in the Java API for JSON Binding
The Java EE 7 Platform: Productivity &amp; HTML5 at San Francisco JUG
Ad

Similar to Practical RESTful Persistence (20)

PPT
RESTful Data Access Services with Java EE
PPT
RESTful services with JAXB and JPA
PPTX
WebLogic Developer Webcast 1: JPA 2.0
PPTX
Rapid prototyping of eclipse rcp applications 2017
PDF
EclipseLink: Beyond Relational and NoSQL to Polyglot and HTML5
PDF
Java persistence api 2.1
PPTX
Introduction to JPA (JPA version 2.0)
PPT
test for jpa spring boot persistence hehe
PDF
Java Persistence API 2.0: An Overview
PDF
Java Persistence API
PPT
PPT
Al rihieli persistence
PPT
Jpa basics
PPTX
Евгений Капинос "Advanced JPA (Java Persistent API)"
PPT
Entity Persistence with JPA
PPT
OSGi Persistence With EclipseLink
PPTX
Jpa 2.1 Application Development
PDF
Enterprise Persistence in OSGi - Mike Keith, Oracle
PPT
ORM Concepts and JPA 2.0 Specifications
PPTX
Jakarta Persistence (JPA) - Web Technologies
RESTful Data Access Services with Java EE
RESTful services with JAXB and JPA
WebLogic Developer Webcast 1: JPA 2.0
Rapid prototyping of eclipse rcp applications 2017
EclipseLink: Beyond Relational and NoSQL to Polyglot and HTML5
Java persistence api 2.1
Introduction to JPA (JPA version 2.0)
test for jpa spring boot persistence hehe
Java Persistence API 2.0: An Overview
Java Persistence API
Al rihieli persistence
Jpa basics
Евгений Капинос "Advanced JPA (Java Persistent API)"
Entity Persistence with JPA
OSGi Persistence With EclipseLink
Jpa 2.1 Application Development
Enterprise Persistence in OSGi - Mike Keith, Oracle
ORM Concepts and JPA 2.0 Specifications
Jakarta Persistence (JPA) - Web Technologies
Ad

More from Shaun Smith (10)

PPTX
A 1.5MB Java Container App? Yes you can!
PPTX
Practical Tips for Hardening Java Applications
PDF
Serverless Java: JJUG CCC 2019
PPTX
Functions and DevOps
PPTX
Democratizing Serverless
PDF
Polyglot! A Lightweight Cloud Platform for Java SE, Node, and More
PDF
Lightweight Java in the Cloud
ODP
EclipseCon 2011-Gemini Naming
ODP
EclipseCon 2011-Gemini Intro
ODP
EclipseCon 2011-Gemini JPA
A 1.5MB Java Container App? Yes you can!
Practical Tips for Hardening Java Applications
Serverless Java: JJUG CCC 2019
Functions and DevOps
Democratizing Serverless
Polyglot! A Lightweight Cloud Platform for Java SE, Node, and More
Lightweight Java in the Cloud
EclipseCon 2011-Gemini Naming
EclipseCon 2011-Gemini Intro
EclipseCon 2011-Gemini JPA

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PPTX
Spectroscopy.pptx food analysis technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
cuic standard and advanced reporting.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Teaching material agriculture food technology
Spectroscopy.pptx food analysis technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Unlocking AI with Model Context Protocol (MCP)
NewMind AI Weekly Chronicles - August'25 Week I
Review of recent advances in non-invasive hemoglobin estimation
sap open course for s4hana steps from ECC to s4
Digital-Transformation-Roadmap-for-Companies.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Mobile App Security Testing_ A Comprehensive Guide.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Programs and apps: productivity, graphics, security and other tools
cuic standard and advanced reporting.pdf
The AUB Centre for AI in Media Proposal.docx
Machine learning based COVID-19 study performance prediction
20250228 LYD VKU AI Blended-Learning.pptx

Practical RESTful Persistence