Top Banner
jeudi 23 février 2012
43

Hibernate OGM - JPA for Infinispan and NoSQL

May 25, 2015

Download

Technology

JBUG London

Presentation by Emmanuel Bernard
presented at the JBUG London Event on the 22nd of February 2012
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Hibernate OGM - JPA for Infinispan and NoSQL

jeudi 23 février 2012

Page 2: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Hibernate OGMJPA for Infinispan and NoSQL

Emmanuel BernardData Platform Architect

but actually doing things

JBoss By Red Hat

jeudi 23 février 2012

Page 3: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Before you leave• JPA for NoSQL

• first key / value (Infinispan)• Denormalization engine• Reuse mature projects• Influenced by the relational model• Does queries too (gradual ramp up)• Early phases

jeudi 23 février 2012

Page 4: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Emmanuel Bernard• Hibernate• JCP• Ceylon• Podcasts

• asylum.jboss.org• lescastcodeurs.com

• The rest is at http://emmanuelbernard.com• @emmanuelbernard

jeudi 23 février 2012

Page 5: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

(No)SQL tour

jeudi 23 février 2012

Page 6: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Relational databases

jeudi 23 février 2012

Page 7: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Relational databases• Data structure abstraction• Transaction, referential integrity• Common query language• (Simple) type• Proven usefulness

• tuning, backup, resilience

jeudi 23 février 2012

Page 8: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Relational databases• (Some) limitations:

• planning for scale is hard• data model changes are painful

• New needs• limitless data for later analysis• instant fame syndrome• less query demanding data

jeudi 23 février 2012

Page 9: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

NoSQL is not new

jeudi 23 février 2012

Page 10: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

NoSQL is not new

jeudi 23 février 2012

Page 11: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

NoSQL is not new

jeudi 23 février 2012

Page 12: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

NoSQL alternatives• Web “giants” needs• Very different Goals

• data size / availability• low latency / higher throughput

• Optimize some data access patterns

jeudi 23 février 2012

Page 13: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

NoSQL families• Graph oriented databases• Key / value stores• Document based stores• BigTable-style

key value

123 Address@23

126 “Booya”

{ "user" : { "id": "124",

"name": "Emmanuel", "addresses" : [

{ "city": "Paris", "country": "France" }, { "city": "Atlanta", "country": "USA" }

]}

1 Things A foo B bar C baz

2 Things C bam E coh People A Emmanuel

3 Languages A C B Java C Ceylon

jeudi 23 février 2012

Page 14: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Flexibility at a cost

jeudi 23 février 2012

Page 15: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Flexibility at a cost• Programming model

• no common API :(• query (Map Reduce, specific DSL, ...)• no schema => app driven schema

• Physical data structure transpires• Transaction / durability / consistency

jeudi 23 février 2012

Page 16: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

JPA for NoSQL

jeudi 23 février 2012

Page 17: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Demo

jeudi 23 février 2012

Page 18: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Goals• Encourage new data usage patterns

• volume, types etc• Familiar environment

• Full JPA support• easy to jump in (and out!)

• Stop talking, act

• “PaaS on Java EE” initiative

jeudi 23 février 2012

Page 19: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

What it does• Today

• JPA front end for Infinispan and more• CRUD support for @Entities• Full-text queries

• Tomorrow• JP-QL queries (simple ones)• Other NoSQL

• The day after• Complex JP-QL queries

jeudi 23 février 2012

Page 20: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Not a silver bullet!

• But JPA matches quite nicely

jeudi 23 février 2012

Page 21: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Hibernate CoreJPA: programmatic API

Innispan

Hibernate Search

searches / indexesstored in

InnispanInnispanInnispanInnispan

distributed key/value store

indexes / searches

Domain modelPOJO

persists

jeudi 23 février 2012

Page 22: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Hibernate CoreJPA: programmatic API

Innispan

Hibernate Search

searches / indexesstored in

Teiid

InnispanInnispanInnispanInnispan

distributed key/value store

indexes / searches

Domain modelPOJO

persists

enables complex joins

and aggregation

jeudi 23 février 2012

Page 23: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Hibernate CoreJPA: programmatic API

Innispan

Hibernate Search

Search engine

searches / indexesstored in

Teiid

InnispanInnispanInnispanInnispan

distributed key/value store

indexes / searches

Domain modelPOJO

persists

enables complex joins

and aggregation

jeudi 23 février 2012

Page 24: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Hibernate CoreJPA: programmatic API

Innispan

Hibernate Search

Search engine

searches / indexesstored in

Teiid

InnispanInnispanInnispanInnispan

distributed key/value store

indexes / searches

Domain modelPOJO

persists

enables complex joins

and aggregation

Hibernate OGMCore

persists into

delegatesobject logic to

delegates search to

JP-QLconverter

jeudi 23 février 2012

Page 25: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Hibernate CoreJPA: programmatic API

Innispan

Hibernate Search

Search engine

searches / indexesstored in

Teiid

InnispanInnispanInnispanInnispan

distributed key/value store

indexes / searches

Domain modelPOJO

persists

enables complex joins

and aggregation

Hibernate OGMCore

persists into

delegatesobject logic to

delegates search to

Object/Grid Mapper

JP-QLconverter

jeudi 23 février 2012

Page 26: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Hibernate CoreJPA: programmatic API

Innispan

Hibernate Search

Search engine

searches / indexesstored in

Teiid

InnispanInnispanInnispanInnispan

distributed key/value store

indexes / searches

Domain modelPOJO

persists

enables complex joins

and aggregation

Hibernate OGMCore

persists into

delegatesobject logic to

delegates search to

Object/Grid Mapper

JP-QLconverter

NoSQL

jeudi 23 février 2012

Page 27: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Concepts

jeudi 23 février 2012

Page 28: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Schema or no schema?• Schema-less

• developer friendly• data structure migration?• need strict development guidelines

• Schema• strong documentation• share with other apps / tooling

jeudi 23 février 2012

Page 29: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Entities as serialized blobs?• Store the whole graph?• Consistency with duplicated objects• Concurrency / latency

• Structure change and (de)serialization

jeudi 23 février 2012

Page 30: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

OGM’s approach• Keep what’s best from relational model

• as much as possible• Decorrelate object and data structure

• object model evolution• Data stored as (self-described) tuples• Limited set of core types• CRUD operations are key lookups

jeudi 23 février 2012

Page 31: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Infinispan• In-memory key / value store + cache store• Data grid

• memory >> network >> local disk access• Transactional

• JTA / XAResource• Distributed

• virtual memory = (sum of servers)/redundancy

jeudi 23 février 2012

Page 32: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Hibernate OGM’s data structure

jeudi 23 février 2012

Page 33: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Storage - Entities• Each entity in a unique key

• table name• id column names and values

• Value is Map<String,Object>• String: column name• Object: simple type (serializable)

jeudi 23 février 2012

Page 34: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Storage - Associations• Cannot store exactly like relational DBs• Simulate navigation to associations

• one key per navigation• Value is the list of tuples• Focus on speedy reads

• writes involve several key lookups

jeudi 23 février 2012

Page 35: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

userIdnameaddresses

User

addressIdcity

Address

userId_pkname

tbl_useraddressId_pkcity

tbl_addressuserId_fkaddressId_fk

tbl_user_address

nn

*1 1*

key value

tbl_user,userId_pk,1 {userId_pk=1,name=�”Emmanuel�”}

tbl_address,addressId_pk,3 {addressId_pk=3,city=�”Paris�”}

tbl_user_address,userId_fk,1 { {userId_fk=1, addressId_fk=3}, {userId_fk=1, addressId_fk=5} }

tbl_address,addressId_pk,5 {addressId_pk=5,city=�”Atlanta�”}

tbl_user_address,addressId_fk,3 { {userId_fk=1, addressId_fk=3}, {userId_fk=2, addressId_fk=3} }

tbl_user,userId_pk,2 {userId_pk=2,name=�”Caroline�”}

tbl_user_address,userId_fk,2 { {userId_fk=2, addressId_fk=3} }

tbl_user_address,addressId_fk,5 { {userId_fk=1, addressId_fk=5} }

jeudi 23 février 2012

Page 36: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

userIdnameaddresses

User

addressIdcity

Address

userId_pkname

tbl_useraddressId_pkcity

tbl_addressuserId_fkaddressId_fk

tbl_user_address

nn

*1 1*

key value

tbl_user,userId_pk,1 {userId_pk=1,name=�”Emmanuel�”}

tbl_address,addressId_pk,3 {addressId_pk=3,city=�”Paris�”}

tbl_user_address,userId_fk,1 { {userId_fk=1, addressId_fk=3}, {userId_fk=1, addressId_fk=5} }

tbl_address,addressId_pk,5 {addressId_pk=5,city=�”Atlanta�”}

tbl_user_address,addressId_fk,3 { {userId_fk=1, addressId_fk=3}, {userId_fk=2, addressId_fk=3} }

tbl_user,userId_pk,2 {userId_pk=2,name=�”Caroline�”}

tbl_user_address,userId_fk,2 { {userId_fk=2, addressId_fk=3} }

tbl_user_address,addressId_fk,5 { {userId_fk=1, addressId_fk=5} }

jeudi 23 février 2012

Page 37: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

userIdnameaddresses

User

addressIdcity

Address

userId_pkname

tbl_useraddressId_pkcity

tbl_addressuserId_fkaddressId_fk

tbl_user_address

nn

*1 1*

key value

tbl_user,userId_pk,1 {userId_pk=1,name=�”Emmanuel�”}

tbl_address,addressId_pk,3 {addressId_pk=3,city=�”Paris�”}

tbl_user_address,userId_fk,1 { {userId_fk=1, addressId_fk=3}, {userId_fk=1, addressId_fk=5} }

tbl_address,addressId_pk,5 {addressId_pk=5,city=�”Atlanta�”}

tbl_user_address,addressId_fk,3 { {userId_fk=1, addressId_fk=3}, {userId_fk=2, addressId_fk=3} }

tbl_user,userId_pk,2 {userId_pk=2,name=�”Caroline�”}

tbl_user_address,userId_fk,2 { {userId_fk=2, addressId_fk=3} }

tbl_user_address,addressId_fk,5 { {userId_fk=1, addressId_fk=5} }

jeudi 23 février 2012

Page 38: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Queries• Hibernate Search indexes entities• Store Lucene indexes in Infinispan• JP-QL to Lucene query

• Works for simple-ish queries

jeudi 23 février 2012

Page 39: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

select a from Animal a where a.size > 20> animalQueryBuilder .range().onField(“size”).above(20).excludeLimit() .createQuery();

select u from Order o join o.user u where o.price > 100 and u.city = “Paris”> orderQB.bool() .must( orderQB.range().onField(“price”) .above(100).excludeLimit().createQuery() ) .must( orderQB.keyword().onField(“user.city”) .matching(“Paris”).createQuery() ) .createQuery();

jeudi 23 février 2012

Page 40: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Future• More NoSQL families• More JP-QL support• JP-QL to “primitives”• API for operations in bulk• More denormalization options• Hybrid deployment options

jeudi 23 février 2012

Page 41: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

Hibernate OGM• JPA for NoSQL (Infinispan initially)• Reuse mature projects• Relational structure• Does queries too

• Status• work in progress• refining the core data structure

jeudi 23 février 2012

Page 42: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

More info• Documentation

• http://ogm.hibernate.org• including reference doc

• Any good JPA book ;)• Code

• come and contribute! It’s fun stuff• https://github.com/hibernate/hibernate-ogm

• Q&A

jeudi 23 février 2012

Page 43: Hibernate OGM - JPA for Infinispan and NoSQL

Copyright 2010-2012 Emmanuel Bernard and Red Hat Inc.

References• Pictures under creative commons • http://www.flickr.com/photos/tomsaint/3415333390/• http://www.flickr.com/photos/anniewong/26473161/ • http://www.flickr.com/photos/jdhancock/5002736203/ • http://www.flickr.com/photos/liutao/280498401• http://www.flickr.com/photos/ehw/243631365/

jeudi 23 février 2012