Using NoSQL with JPA, CDI and Java EE

65,024 views
66,388 views

Published on

This session explores how NoSQL solutions like MongoDB, Cassandra, Neo4j, HBase and CouchDB can be used in a Java EE application with or without a JPA facade. Although the primary focus is on EclipseLink NoSQL, we will also cover Hibernate OGM, EasyCassandra, Morphia, etc as well as seeing how NoSQL can be used natively via basic CDI injection.

Published in: Technology
0 Comments
33 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
65,024
On SlideShare
0
From Embeds
0
Number of Embeds
41,562
Actions
Shares
0
Downloads
323
Comments
0
Likes
33
Embeds 0
No embeds

No notes for slide

Using NoSQL with JPA, CDI and Java EE

  1. 1. Others Talk, We Listen. Using NoSQL with JPA, CDI and Java EE Reza Rahman Senior Architect rrahman@captechconsulting.com @reza_rahman
  2. 2. CapTech Full-service US national IT consulting firm that focuses on client best interests, trust, servant leadership, culture, professionalism and technical excellence. #28 in Vault's Consulting Top 50 #3 Best Consulting Internship #9 Best Overall Internship #1 in Meeting Client’s Needs #7 Best Firm to Work For #1 in Career Development Ranked for the 7th Consecutive Year Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  3. 3. Agenda • NoSQL Landscape • Using NoSQL with JPA • Using NoSQL with CDI Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  4. 4. NoSQL Landscape • Non-conformance to established RDMS paradigm • No SQL/queries, no schemas, weak referential integrity, no JOINs • Scalability and cost major motivators • ACID vs. BASE • Unstructured data minor motivator • Mostly complement and not replace relational databases • Extremely divergent, specialized products • Some taxonomies • Key/value, document, graph, etc • MongoDB, Cassandra, Google BigTable, CouchDB, HBase, Redis, Neo4j Copyright © 2015 CapTech Ventures, Inc. All rights reserved. Wild, Wild West
  5. 5. NoSQL Landscape Copyright © 2015 CapTech Ventures, Inc. All rights reserved. Adoption and Trends
  6. 6. Putting NoSQL in Perspective Copyright © 2015 CapTech Ventures, Inc. All rights reserved. Probably Not a Replacement to RDBMS
  7. 7. The Case for JPA • There almost always is a domain model • Most of JPA fits NoSQL quite well • Learning each diverging NoSQL product cumbersome, often unnecessary • Switching between NoSQL solutions difficult • “Polyglot Persistence” difficult • NoSQL APIs generally low level, verbose Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  8. 8. Applying JPA to NoSQL • JPA domain model concepts apply well to NoSQL • Entities, Embeddables, OneToOne, OneToMany, ManyToOne, ManyToMany • Pure relational concepts may not apply well • Table, Column, JoinTable, JoinColumn • JPA queries can fit relatively well • Basic finders (by identity, all) • JPQL—portable query language defined by the spec • Native query—lets you leverage database specific features Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  9. 9. EclipseLink NoSQL • Support JPA style access to NoSQL databases • Leverage existing non-relational database support • Metadata to identify NoSQL entities (e.g. @NoSQL) • Support JPQL subset • Leverage what’s 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 © 2015 CapTech Ventures, Inc. All rights reserved.
  10. 10. JPA NoSQL Demo https://github.com/m-reza-rahman/jpa-nosql-demo Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  11. 11. Other JPA/NoSQL Solutions • Hibernate OGM • Utilizes Hibernate codebase for NoSQL • MongoDB, Cassandra, Neo4J, CouchDB, Infinispan, Ehcache • Tries to provide as much of JPA as possible, including queries via Hibernate Search/Lucene, relational mapping annotations • DataNucleus • Persistence layer behind Google App Engine • MongoDB, Cassandra, HBase, Neo4J • Kundera • Cassandra, MongoDB, HBase, Redis, Neo4J, Oracle NoSQL, CouchDB Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  12. 12. 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 evolving around CDI Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  13. 13. A Quick Look at CDI • Basic dependency injection • @Inject, @Qualifier, @Named, @Stereotype, @Alternative, @Produces, @Disposes • Context management • @RequestScoped, @SessionScoped, @ConversationScoped, @ApplicationScoped, @FlowScoped, @TransactionScoped • Lightweight Events • Event, @Observes • Interceptors/Decorators • @Interceptor, @Decorator • Portable Extensions SPI Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  14. 14. 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 Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  15. 15. CDI NoSQL Demo https://github.com/m-reza-rahman/cdi-nosql-demo Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  16. 16. Summary • NoSQL has uses, but still immature, niche and volatile • JPA can apply well to NoSQL – many such initiatives • Most NoSQL APIs are good enough to integrate directly via CDI Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  17. 17. Resources • Considerations for Using NoSQL on Your Next Project • http://www.slideshare.net/VeryFatBoy/bcs-2013 • EclipseLink NoSQL Examples • http://wiki.eclipse.org/EclipseLink/Examples/JPA/NoSQL • Hibernate OGM • http://hibernate.org/ogm/ • DataNucleus • http://www.datanucleus.org • Kundera • https://github.com/impetus-opensource/Kundera/ • CDI • http://www.cdi-spec.org Copyright © 2015 CapTech Ventures, Inc. All rights reserved.
  18. 18. Copyright © 2015 CapTech Ventures, Inc. All rights reserved.

×