Sie sind auf Seite 1von 20

Using NoSQL with JPA, EclipseLink and Java EE

Reza Rahman Java EE/GlassFish Evangelist reza.rahman@oracle.com

Program Agenda

NoSQL Landscape Using NoSQL with ~JPA Using NoSQL with CDI

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

Public

NoSQL Landscape
Wild, Wild West
Defined by non-conformance to established RDMS paradigm
No SQL/queries, schemaless, weak referential integrity, no JOINs

Scalability and cost major motivators (ACID vs. BASE)


No transactions, eventual consistency, distributed nodes

Extremely divergent, specialized products Some taxonomies


Key/value, document, graph, columnar, etc

MongoDB, Cassandra, Google BigTable, CouchDB, HBase,

Neo4j, Oracle NoSQL

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

Public

NoSQL Landscape
Adoption and Trends

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

Public

The Case for JPA


Learning each diverging NoSQL product cumbersome, often

unnecessary Some parts of JPA fit NoSQL quite well Switching between NoSQL solutions difficult, particularly at various stages of application development Polyglot Persistence difficult NoSQL APIs generally low level, verbose

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

Public

EclipseLink NoSQL
Support JPA style access to NoSQL databases
Leverage non-relational database support for JCA

Metadata to identify NoSQL entities (e.g., @NoSQL) Support JPQL subset for each
Leverage whats available

Initial support for MongoDB and Oracle NoSQL More to come (Cassandra, HBase, CouchDB?) Support mixing relational and non-relational data in single

composite persistence unit (polyglot persistence)

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

Public

Applying JPA to NoSQL


Core JPA concepts apply well to NoSQL
Entities, Embeddables, ElementCollection, OneToOne, OneToMany,

ManyToOne, Version
Some concepts apply with some databases
JPQL, NamedNativeQuery

Pure relational concepts dont apply well


CollectionTable, Column, SecondaryTable,

SequenceGenerator, TableGenerator

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

Public

Querying NoSQL with JPA


Three kinds of queries
Basic finders (by identity, all) JPQLportable query language defined by the spec Native querylets you leverage database specific features Dynamic or static @NamedQuery

JPQL translated to underlying database query API

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

Public

Example MongoDB Mapped Entity

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

Public

MongoDB Query Examples


JPQL
select o from Order o where o.totalCost > 1000 select o from Order o where o.description like Pinball% select o from Order o join o.orderLines l where l.cost > :cost

Native Queries
query = entityManager.createNativeQuery( "db.ORDER.findOne({\"_id\":\"" + oid + "\"})",
Order.class); Order order = (Order) query.getSingleResult();

10

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

Public

JPA/EclipseLink NoSQL Demo

https://github.com/m-reza-rahman/jpa-nosql-demo

11

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

Public

Other JPA/NoSQL Solutions


Hibernate OGM
Utilizes Hibernate codebase for NoSQL MongoDB, Neo4J, Infinispan, Ehcache Tries to provide as much of JPA as possible, including queries via

Hibernate Search/Lucene, relational mapping annotations


Somewhat rigid storage requirements

DataNucleus
Persistence layer behind Google App Engine (not JPA compliant) MongoDB, HBase, Neo4j

Kundera
Cassandra, MongoDB, HBase

Easy-Cassandra
Cassandra only

12

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

Public

Similar NoSQL Solutions


PlayOrm
NoSQL centric JPA flavored annotations Somewhat focused on Play framework Cassandra, MongoDB, HBase

Mophia
Annotations mirror JPA MongoDB specific

13

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

Public

CDI Overview
Next-generation dependency injection for Java EE
Synthesizes best ideas from Seam 2, Guice and Spring Many innovative features on its own right Focus on loose-coupling, Java-centric type-safety, annotations,

expressiveness and ease-of-use Large ecosystem rapidly evolving around CDI

14

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

Public

A Quick Look at CDI


Basic dependency injection
@Inject, @Qualifier, @Named, @Stereotype,

@Alternative, @Produces, @Disposes


Context management
@Dependent, @RequestScoped, @SessionScoped,

@ConversationScoped, @ApplicationScoped
Lightweight Events
Event, @Observes

Interceptors/Decorators
@Interceptor, @Decorator

Portable Extensions SPI

15

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

Public

The Case for CDI


Hibernate OGM is not expected to be the Rosetta stone used to

interact with all NoSQL solutions in all use cases No real domain model Advanced, highly specialized features Unsupported NoSQL solutions Existing NoSQL API knowledge Most NoSQL APIs POJO based, easy to integrate natively via CDI

16

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

Public

CDI NoSQL Demo

https://github.com/m-reza-rahman/cdi-nosql-demo

17

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

Public

Summary
NoSQL market fast growing, but still immature and volatile Parts of JPA can apply well to NoSQL many such initiatives

including from Oracle Get involved! Most NoSQL APIs are good enough to integrate directly via CDI Should NoSQL be standardized in Java EE 8?

18

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

Public

Resources
EclipseLink NoSQL Examples
http://wiki.eclipse.org/EclipseLink/Examples/JPA/NoSQL

Oracle NoSQL
http://www.oracle.com/technetwork/database/database-

technologies/nosqldb
Hibernate OGM
http://www.hibernate.org/subprojects/ogm.html

DataNucleus
http://www.datanucleus.org

Kundera
https://github.com/impetus-opensource/Kundera/

Easy-Cassandra
https://github.com/otaviojava/Easy-Cassandra

19

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

Public

Resources
PlayOrm
https://github.com/deanhiller/playorm

Mophia
http://code.google.com/p/morphia/

Weld Docs
http://docs.jboss.org/weld/reference/latest/en-US/html/

20

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

Public

Das könnte Ihnen auch gefallen