SlideShare a Scribd company logo
1 of 40
Download to read offline
MongoDB Berlin 2013:
Java Persistence Frameworks for MongoDB


Tobias.Trelle@codecentric.de / @
codecentric AG
                               @tobiastrelle
Tobias Trelle

                 -   Senior IT Consultant
                     @ codecentric AG
                     (official 10gen partner)
                      official

                 -   Conference talks on MongoDB

                 -   MongoDB user group
                     Düsseldorf/Germany

                 -   Authoring a German book on
                     MongoDB
codecentric AG
Where have all my tables gone …




                 ORM          is dead


                 long live   ODM
codecentric AG
Agenda


− MongoDB Java D
               Driver

− Spring Data MongoDB

− Morphia
− Hibernate OGM
codecentric AG
Use Case




codecentric AG
Mongo Java Driver


codecentric AG
MongoDB Drivers


− One wire protocol for all client languages

− A driver implementation per language

− Responsibilities:
       −     Converting language dependent data structures   BSON

       −     Generating ObjectId for _id field


− Overview: http://www.mongodb.org/display/DOCS/Drivers
                   www.mongodb.org/display/DOCS/Drivers

codecentric AG
MongoDB Java Driver


− One JAR w/o further dependencies
                       ependencies:

     <dependency>
        <groupId>org.mongodb</
                            </groupId>
        <artifactId>mongo-java
                          java-driver</artifactId>
        <version>2.10.0</version
                         version>
     </dependency>

− github:
     https://github.com/mongodb/mongo
             github.com/mongodb/mongo-java-driver



codecentric AG
Java Driver: Connect to MongoDB

import com.mongodb.MongoClient
       com.mongodb.MongoClient;

// Default: localhost:27017
mongo = new MongoClient();

// Sharding: mongos server
mongo = new MongoClient("mongos01" 4711);
                        "mongos01",

// Replica set
mongo = new MongoClient(Arrays.
                        Arrays.asList(
     new ServerAddress("replicant01" 10001),
                       "replicant01",
     new ServerAddress("replicant02" 10002),
                       "replicant02",
     new ServerAddress("replicant03" 10003)
                       "replicant03",
     ));
codecentric AG
Java Driver: Database / Collection

import com.mongodb.DB
       com.mongodb.DB;
import com.mongodb.DBCollection
       com.mongodb.DBCollection;

DB db = mongo.getDB
        mongo.getDB("test");

DBCollection collection =
   db.getCollection("foo");
   db.getCollection

codecentric AG
Java Driver: Documents

import com.mongodb.BasicDBObject
       com.mongodb.BasicDBObject;
import com.mongodb.DBObject
       com.mongodb.DBObject;

// insert document
DBObject doc = new BasicDBObject();
doc.put("date", new Date());
doc.put("i", 42);

collection.insert(doc
                  doc);
codecentric AG
Java Driver: Queries

import com.mongodb.DBCursor
       com.mongodb.DBCursor;

DBCursor cursor;

cursor = collection.find(); // all documents
                        ();

// documents w/ {i: 42}
cursor = collection.find(
                        (
     new BasicDBObject("i
                        i", 42) );

document = cursor.next();
                      ();
...
codecentric AG
Java Driver: Order Use Case
DB db = mongo.getDB("test");
DBCollection collection = db.getCollection("order"
                                           "order");
DBObject order;
List<DBObject> items = new ArrayList<DBObject>();
                                             >();
DBObject item;

// order
order = new BasicDBObject();
order.put("date", new Date());
order.put("custInfo" , "Tobias Trelle");
order.put("items", items);
// items
item = new BasicDBObject();
item.put("quantity", 1);
item.put("price", 47.11);
item.put("desc", "Item #1");
items.add(item);
item = new BasicDBObject();
item.put("quantity", 2);
item.put("price", 42.0);
item.put("desc", "Item #2");
items.add(item);

collection.insert(order);

codecentric AG
Spring Data
                  MongoDB

codecentric AG
Spring Data MongoDB – Fact Sheet



  Vendor          VMware / SpringSource
  License         Apache License Version 2.0
                         License,
  Documentation   http://www.springsource.org/spring-data/mongodb
                  http://www.springsource.org/spring
  Main Features   • Repository Support
                  • Object/Document Mapping
                           Document
                  • Templating




codecentric AG
Spring Data
Common patterns for RDBMS and NoSQL data stores

                                            Spring Data
                                  CrudRepository     PagingAndSortingRepository

                  Spring Data      Spring Data          Spring Data           Spring Data
                      JPA           MongoDB               Neo4j                    …
                 JpaRepository   MongoRepository      GraphRepository
                                 MongoTemplate         Neo4jTemplate


                                                      Embedded     REST


                      JPA        Mongo Java Driver

                     JDBC



                    RDBMS             MongoDB              Neo4j                   …



Quelle: http://www.infoq.com/articles/spring
        http://www.infoq.com/articles/spring-data-intro
codecentric AG
Spring Data MongoDB

Templating
       −     Resource abstraction
       −     Configure connections to mongod / mongos node(s)
       −     Collection lifecycle ( create, drop)
       −     Map/Reduce / Aggregation


Object Mapping
       −     Annotation based: @Document, @Field, @Index etc.
                                        ,
       −     Classes are mapped to collections, Java Objects to documents
                                              ,


Repository Support
       −     Queries are derived from methods signatures
       −     Geospatial Queries




codecentric AG
Spring Data MongoDB Template
Configuration

     <!-- Connection to MongoDB server --
                                       -->
     <mongo:db-factory host="localhost" port
                                        port="27017" dbname="test" />


     <!-- MongoDB Template -->
     <bean id="mongoTemplate"
          class="org.springframework.data.mongodb.core.MongoTemplate
                 org.springframework.data.mongodb.core.MongoTemplate">
          <constructor-arg name="mongoDbFactory ref="mongoDbFactory"/>
                                 mongoDbFactory"
     </bean>

Usage

     @Autowired MongoTemplate template;

     template.indexOps(Location.class).ensureIndex
                                       ensureIndex(
          new GeospatialIndex("position") );
                                        )

codecentric AG
Spring Data MongoDB: Object Mapping
public class Order {
  @Id private String id;
  private Date date;
  @Field("custInfo") private String customerInfo;
  List<Item> items; ...
}

public class Item {
  private int quantity;
  private double price;
  @Field("desc") private String description
                                description;
  ...
}


codecentric AG
Spring Data MongoDB: Repository Support

public interface OrderRepository extends
  MongoRepository<Order, String> {
                 <Order,

                 findByItemsQuantity(int quantity);
     List<Order> findByItemsQuantity

                 findByItemsPriceGreaterThan(double price);
     List<Order> findByItemsPriceGreaterThan

}




codecentric AG
Spring Data MongoDB: Repository Support


−      Main Concept:

     use the signature of a method to derive the query (at runtime)

−      Base Implementations / abstractions for

       −     CRUD operations

       −     Paging

       −     Sorting



codecentric AG
Spring Data MongoDB: Additional Goodies


−       Map/Reduce / Aggregation framework

− Index Management

− Support for GridFS

− Geopspatial indexes / queries

− Optimistic Locking
codecentric AG
Hibernate OGM


codecentric AG
Hibernate OGM MongoDB – Fact Sheet



  Vendor          JBoss / Redhat
  License         GNU LGPL, Version 2.1
                          ,
  Documentation   http://www.hibernate.org/subprojects/ogm.html
  Main Features   • JPA API (Subset
                             Subset)
                  • JPQL Query Language




codecentric AG
Hibernate OGM


− Implements JPA API (subset)

− JP-QL query are translated to native
     QL
     datastore queries

− Supports Infinispan, EhCache, MongoDB
                     ,


codecentric AG
Hibernate OGM
Architecture




Source:
http://docs.jboss.org/hibernate/ogm/4.0/reference
    /en-US/html/ogm-architecture.html#d0e409
codecentric AG
Hibernate OGM MongoDB: Configuration

<persistence version="2.0" …>
     <persistence-unit name="primary">
         <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence
                                         HibernateOgmPersistence</provider>
         <class>hibernate.Order</class>
          <class>hibernate.Item</class>
         <properties>
                 <property name="hibernate.ogm.datastore.provider
                                   hibernate.ogm.datastore.provider"
                 value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"
                       "org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
                 <property name="hibernate.ogm.mongodb.database value=„odm"/>
                                 hibernate.ogm.mongodb.database"
                 <property name="hibernate.ogm.mongodb.host value=„localhost"/>
                                 hibernate.ogm.mongodb.host"
                 <property name="hibernate.ogm.mongodb.port value=„27017"/>
                                 hibernate.ogm.mongodb.port"
         </properties>
     </persistence-unit>
</persistence>



codecentric AG
Hibernate OGM MongoDB: Object Mapping

@Entity
@NamedQuery(
     name="byItemsQuantity",
     query = "SELECT o FROM Order o JOIN o.items i WHERE i.quantity = :quantity"
     )
public class Order {
     @GeneratedValue(generator = "uuid")
     @GenericGenerator(name = "uuid", strategy = "uuid2"
                                                 "uuid2")
     @Id private String id;


     private Date date;


     @Column(name = "custInfo") private String customerInfo
                                               customerInfo;


     @ElementCollection
     private List<Item> items;



codecentric AG
Hibernate OGM MongoDB: Object Mapping

@Embeddable
public class Item {


     private int quantity;


     private double price;


     @Column(name="desc") private String description
                                         description;
     ...




codecentric AG
Hibernate OGM: Summary


− Very early beta

− Only persist / merge / remove
   nly

− No query support (yet)
   o

− Uses relational API
codecentric AG
Hibernate OGM: OgmEntityManager




codecentric AG
Morphia


codecentric AG
Morphia – Fact Sheet



  Developer       Scott Hernandez, James Green
  License         Apache License Version 2.0
                         License,
  Documentation   https://github.com/jmkgreen/morphia/wiki/Overview
  Main Features   • Object/Document Mapping
                           Document
                  • Custom Query API
                  • DAO support




codecentric AG
Morphia: Object Mapping

public class Order {
     @Id private ObjectId id;
     private Date date;
     @Property("custInfo") private String customerInfo;
     @Embedded List<Item> items;
     ...
}
public class Item {
     private int quantity;
     private double price;
     @Property("desc") private String description
                                      description;
     ...
}


codecentric AG
Morphia: Queries

public class OrderDao extends BasicDAO
                              BasicDAO<Order, ObjectId> {


     List<Order> findByItemsQuantity(int quantity) {
                 return
                 find( createQuery().filter("items.quantity
                                             items.quantity", quantity))
                 .asList();
     }
                 findByItemsPriceGreaterThan(double price) {
     List<Order> findByItemsPriceGreaterThan
                 return
                 find( createQuery().field("items.price
                                            items.price").greaterThan(price) )
                 .asList();
     }
     …
}

codecentric AG
Morphia: Custom query syntax – why?


             Morphia       Mongo Query
             =             $eq
                           $
             !=, <>        $neq
                           $
             >, <, >=,<=   $gt,
                           $ $lt, $gte, $lte
             in, nin       $in, $
                                $nin
             elem          $elemMatch
                           $
             …             ….




codecentric AG
Judge yourself …


Spring Data MongoDB
https://github.com/ttrelle/spring-data-examples
https://github.com/ttrelle/spring

Hibernate OGM MongoDB
https://github.com/ttrelle/hibernate
        github.com/ttrelle/hibernate-ogm-examples

Morphia
https://github.com/ttrelle/morphia
        github.com/ttrelle/morphia-mongodb-examples


codecentric AG
Which one should I use?
                                               High
                                            Abstraction

                                     Spring Data
                                      MongoDB
    JPA              Hibernate OGM                          Morphia


Enterprise                                                               Custom
Standard                                                                   API


                                                          MongoDB Java
   JDBC                                                      Driver

                                              Low
                                           Abstraction
    codecentric AG
German MongoDB User Groups (MUGs)

MUG Düsseldorf                         MUG Berlin
https://www.xing.com/net/mongodb-dus   http://www.meetup.com/MUGBerlin/
@MongoDUS                              @MUGBerlin


MUG Frankfurt/Main                     Hamburg MUG
https://www.xing.com/net/mongodb-ffm   https://www.xing.com/net/mugh
@MongoFFM


MUG München
http://www.meetup.com/Muenchen-MongoDB
                               MongoDB-User-Group/
@mongomuc




codecentric AG
QUESTIONS?

Tobias Trelle

codecentric AG
Merscheider Str. 1
42699 Solingen

tel              +49 (0) 212.233628.47
fax              +49 (0) 212.233628.79
mail             Tobias.Trelle@codecentric.de
twitter @tobiastrelle




www.codecentric.de
blog.codecentric.de/en/author/tobias-trelle
                                     trelle
www.xing.com/net/mongodb-dus

codecentric AG

More Related Content

What's hot

[243]kaleido 노현걸
[243]kaleido 노현걸[243]kaleido 노현걸
[243]kaleido 노현걸NAVER D2
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesBrett Meyer
 
Architecture jee principe de inversion de controle et injection des dependances
Architecture jee principe de inversion de controle et injection des dependancesArchitecture jee principe de inversion de controle et injection des dependances
Architecture jee principe de inversion de controle et injection des dependancesENSET, Université Hassan II Casablanca
 
Les Ontologies dans les Systèmes d’Information
Les Ontologies dans les Systèmes d’InformationLes Ontologies dans les Systèmes d’Information
Les Ontologies dans les Systèmes d’Informationcatherine roussey
 
Cours design pattern m youssfi partie 1 introduction et pattern strategy
Cours design pattern m youssfi partie 1 introduction et pattern strategyCours design pattern m youssfi partie 1 introduction et pattern strategy
Cours design pattern m youssfi partie 1 introduction et pattern strategyENSET, Université Hassan II Casablanca
 
SYSTEMES-INTERACTIFS-D-AIDE-A-LA-DECISION-SIAD-1.pdf
SYSTEMES-INTERACTIFS-D-AIDE-A-LA-DECISION-SIAD-1.pdfSYSTEMES-INTERACTIFS-D-AIDE-A-LA-DECISION-SIAD-1.pdf
SYSTEMES-INTERACTIFS-D-AIDE-A-LA-DECISION-SIAD-1.pdfDhiaeddineabdelli
 
Cache in API Gateway
Cache in API GatewayCache in API Gateway
Cache in API GatewayGilWon Oh
 
Intelligence Artificielle : Introduction à l'intelligence artificielle
Intelligence Artificielle : Introduction à l'intelligence artificielleIntelligence Artificielle : Introduction à l'intelligence artificielle
Intelligence Artificielle : Introduction à l'intelligence artificielleECAM Brussels Engineering School
 
What is tackled in the Java EE Security API (Java EE 8)
What is tackled in the Java EE Security API (Java EE 8)What is tackled in the Java EE Security API (Java EE 8)
What is tackled in the Java EE Security API (Java EE 8)Rudy De Busscher
 
Angular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHTAngular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHTtayebbousfiha1
 
현업 엔지니어의 시각에서 본 알고리즘 공부의 장점과 단점
현업 엔지니어의 시각에서 본 알고리즘 공부의 장점과 단점현업 엔지니어의 시각에서 본 알고리즘 공부의 장점과 단점
현업 엔지니어의 시각에서 본 알고리즘 공부의 장점과 단점Wonha Ryu
 
ER 2016 Tutorial
ER 2016 TutorialER 2016 Tutorial
ER 2016 TutorialRim Moussa
 
What’s New in Spring Data MongoDB
What’s New in Spring Data MongoDBWhat’s New in Spring Data MongoDB
What’s New in Spring Data MongoDBVMware Tanzu
 

What's hot (20)

[243]kaleido 노현걸
[243]kaleido 노현걸[243]kaleido 노현걸
[243]kaleido 노현걸
 
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and CapabilitiesNot Just ORM: Powerful Hibernate ORM Features and Capabilities
Not Just ORM: Powerful Hibernate ORM Features and Capabilities
 
Architecture jee principe de inversion de controle et injection des dependances
Architecture jee principe de inversion de controle et injection des dependancesArchitecture jee principe de inversion de controle et injection des dependances
Architecture jee principe de inversion de controle et injection des dependances
 
Les Ontologies dans les Systèmes d’Information
Les Ontologies dans les Systèmes d’InformationLes Ontologies dans les Systèmes d’Information
Les Ontologies dans les Systèmes d’Information
 
Cours design pattern m youssfi partie 1 introduction et pattern strategy
Cours design pattern m youssfi partie 1 introduction et pattern strategyCours design pattern m youssfi partie 1 introduction et pattern strategy
Cours design pattern m youssfi partie 1 introduction et pattern strategy
 
SYSTEMES-INTERACTIFS-D-AIDE-A-LA-DECISION-SIAD-1.pdf
SYSTEMES-INTERACTIFS-D-AIDE-A-LA-DECISION-SIAD-1.pdfSYSTEMES-INTERACTIFS-D-AIDE-A-LA-DECISION-SIAD-1.pdf
SYSTEMES-INTERACTIFS-D-AIDE-A-LA-DECISION-SIAD-1.pdf
 
Cache in API Gateway
Cache in API GatewayCache in API Gateway
Cache in API Gateway
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Intelligence Artificielle : Introduction à l'intelligence artificielle
Intelligence Artificielle : Introduction à l'intelligence artificielleIntelligence Artificielle : Introduction à l'intelligence artificielle
Intelligence Artificielle : Introduction à l'intelligence artificielle
 
Machine Learning
Machine LearningMachine Learning
Machine Learning
 
Sécurité des Applications Web avec Json Web Token (JWT)
Sécurité des Applications Web avec Json Web Token (JWT)Sécurité des Applications Web avec Json Web Token (JWT)
Sécurité des Applications Web avec Json Web Token (JWT)
 
Histoire du big data
Histoire du big dataHistoire du big data
Histoire du big data
 
What is tackled in the Java EE Security API (Java EE 8)
What is tackled in the Java EE Security API (Java EE 8)What is tackled in the Java EE Security API (Java EE 8)
What is tackled in the Java EE Security API (Java EE 8)
 
Angular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHTAngular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHT
 
현업 엔지니어의 시각에서 본 알고리즘 공부의 장점과 단점
현업 엔지니어의 시각에서 본 알고리즘 공부의 장점과 단점현업 엔지니어의 시각에서 본 알고리즘 공부의 장점과 단점
현업 엔지니어의 시각에서 본 알고리즘 공부의 장점과 단점
 
Hibernate
HibernateHibernate
Hibernate
 
ER 2016 Tutorial
ER 2016 TutorialER 2016 Tutorial
ER 2016 Tutorial
 
Support de cours entrepise java beans ejb m.youssfi
Support de cours entrepise java beans ejb m.youssfiSupport de cours entrepise java beans ejb m.youssfi
Support de cours entrepise java beans ejb m.youssfi
 
What’s New in Spring Data MongoDB
What’s New in Spring Data MongoDBWhat’s New in Spring Data MongoDB
What’s New in Spring Data MongoDB
 
Polymorphisme
PolymorphismePolymorphisme
Polymorphisme
 

Viewers also liked

MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
MongoDB + Java + Spring Data
MongoDB + Java + Spring DataMongoDB + Java + Spring Data
MongoDB + Java + Spring DataAnton Sulzhenko
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Hermann Hueck
 
Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Tobias Trelle
 
Dropwizard with MongoDB and Google Cloud
Dropwizard with MongoDB and Google CloudDropwizard with MongoDB and Google Cloud
Dropwizard with MongoDB and Google CloudYun Zhi Lin
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBTobias Trelle
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...mfrancis
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010Eliot Horowitz
 
Building a web application with MongoDB & Java
Building a web application with MongoDB & JavaBuilding a web application with MongoDB & Java
Building a web application with MongoDB & JavaTrisha Gee
 
Building Spring Data with MongoDB
Building Spring Data with MongoDBBuilding Spring Data with MongoDB
Building Spring Data with MongoDBMongoDB
 
WebEngage demo at Unpluggd (Nov, 2011)
WebEngage demo at Unpluggd (Nov, 2011)WebEngage demo at Unpluggd (Nov, 2011)
WebEngage demo at Unpluggd (Nov, 2011)Avlesh Singh
 
Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentationsourabh aggarwal
 
Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Kuo-Chun Su
 
The Spring Data MongoDB Project
The Spring Data MongoDB ProjectThe Spring Data MongoDB Project
The Spring Data MongoDB ProjectMongoDB
 
Mongo sf easy java persistence
Mongo sf   easy java persistenceMongo sf   easy java persistence
Mongo sf easy java persistenceScott Hernandez
 
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...OpenBlend society
 
Java driver for mongo db
Java driver for mongo dbJava driver for mongo db
Java driver for mongo dbAbhay Pai
 

Viewers also liked (20)

MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
MongoDB + Java + Spring Data
MongoDB + Java + Spring DataMongoDB + Java + Spring Data
MongoDB + Java + Spring Data
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8
 
Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Spring Data, Jongo & Co.
Spring Data, Jongo & Co.
 
Dropwizard with MongoDB and Google Cloud
Dropwizard with MongoDB and Google CloudDropwizard with MongoDB and Google Cloud
Dropwizard with MongoDB and Google Cloud
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
 
The seven deadly sins of microservices
The seven deadly sins of microservicesThe seven deadly sins of microservices
The seven deadly sins of microservices
 
Cadastro Desktop (Swing) com JPA MySQL
Cadastro Desktop (Swing) com JPA MySQLCadastro Desktop (Swing) com JPA MySQL
Cadastro Desktop (Swing) com JPA MySQL
 
Building a web application with MongoDB & Java
Building a web application with MongoDB & JavaBuilding a web application with MongoDB & Java
Building a web application with MongoDB & Java
 
Building Spring Data with MongoDB
Building Spring Data with MongoDBBuilding Spring Data with MongoDB
Building Spring Data with MongoDB
 
WebEngage demo at Unpluggd (Nov, 2011)
WebEngage demo at Unpluggd (Nov, 2011)WebEngage demo at Unpluggd (Nov, 2011)
WebEngage demo at Unpluggd (Nov, 2011)
 
MongoDB + Spring
MongoDB + SpringMongoDB + Spring
MongoDB + Spring
 
Spring 4 final xtr_presentation
Spring 4 final xtr_presentationSpring 4 final xtr_presentation
Spring 4 final xtr_presentation
 
Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Spring Data MongoDB 介紹
Spring Data MongoDB 介紹
 
The Spring Data MongoDB Project
The Spring Data MongoDB ProjectThe Spring Data MongoDB Project
The Spring Data MongoDB Project
 
Mongo sf easy java persistence
Mongo sf   easy java persistenceMongo sf   easy java persistence
Mongo sf easy java persistence
 
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
Introducing Hibernate OGM: porting JPA applications to NoSQL, Sanne Grinovero...
 
Java driver for mongo db
Java driver for mongo dbJava driver for mongo db
Java driver for mongo db
 

Similar to Java Persistence Frameworks for MongoDB

BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBTobias Trelle
 
Morphia, Spring Data & Co.
Morphia, Spring Data & Co.Morphia, Spring Data & Co.
Morphia, Spring Data & Co.Tobias Trelle
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsMongoDB
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsMongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBChun-Kai Wang
 
MongoDB et Hadoop
MongoDB et HadoopMongoDB et Hadoop
MongoDB et HadoopMongoDB
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introductionTse-Ching Ho
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012sullis
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo dbAmit Thakkar
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHPichikaway
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRick Copeland
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
MongoDB and Hadoop: Driving Business Insights
MongoDB and Hadoop: Driving Business InsightsMongoDB and Hadoop: Driving Business Insights
MongoDB and Hadoop: Driving Business InsightsMongoDB
 

Similar to Java Persistence Frameworks for MongoDB (20)

BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
 
Morphia, Spring Data & Co.
Morphia, Spring Data & Co.Morphia, Spring Data & Co.
Morphia, Spring Data & Co.
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
 
Mongodb
MongodbMongodb
Mongodb
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB et Hadoop
MongoDB et HadoopMongoDB et Hadoop
MongoDB et Hadoop
 
MongoDB and Hadoop
MongoDB and HadoopMongoDB and Hadoop
MongoDB and Hadoop
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
 
Rails with mongodb
Rails with mongodbRails with mongodb
Rails with mongodb
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and Python
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
MongoDB and Hadoop: Driving Business Insights
MongoDB and Hadoop: Driving Business InsightsMongoDB and Hadoop: Driving Business Insights
MongoDB and Hadoop: Driving Business Insights
 

More from MongoDB

MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump StartMongoDB
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB
 
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDBMongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDBMongoDB
 

More from MongoDB (20)

MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
 
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDBMongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
 

Java Persistence Frameworks for MongoDB

  • 1. MongoDB Berlin 2013: Java Persistence Frameworks for MongoDB Tobias.Trelle@codecentric.de / @ codecentric AG @tobiastrelle
  • 2. Tobias Trelle - Senior IT Consultant @ codecentric AG (official 10gen partner) official - Conference talks on MongoDB - MongoDB user group Düsseldorf/Germany - Authoring a German book on MongoDB codecentric AG
  • 3. Where have all my tables gone … ORM is dead long live ODM codecentric AG
  • 4. Agenda − MongoDB Java D Driver − Spring Data MongoDB − Morphia − Hibernate OGM codecentric AG
  • 7. MongoDB Drivers − One wire protocol for all client languages − A driver implementation per language − Responsibilities: − Converting language dependent data structures BSON − Generating ObjectId for _id field − Overview: http://www.mongodb.org/display/DOCS/Drivers www.mongodb.org/display/DOCS/Drivers codecentric AG
  • 8. MongoDB Java Driver − One JAR w/o further dependencies ependencies: <dependency> <groupId>org.mongodb</ </groupId> <artifactId>mongo-java java-driver</artifactId> <version>2.10.0</version version> </dependency> − github: https://github.com/mongodb/mongo github.com/mongodb/mongo-java-driver codecentric AG
  • 9. Java Driver: Connect to MongoDB import com.mongodb.MongoClient com.mongodb.MongoClient; // Default: localhost:27017 mongo = new MongoClient(); // Sharding: mongos server mongo = new MongoClient("mongos01" 4711); "mongos01", // Replica set mongo = new MongoClient(Arrays. Arrays.asList( new ServerAddress("replicant01" 10001), "replicant01", new ServerAddress("replicant02" 10002), "replicant02", new ServerAddress("replicant03" 10003) "replicant03", )); codecentric AG
  • 10. Java Driver: Database / Collection import com.mongodb.DB com.mongodb.DB; import com.mongodb.DBCollection com.mongodb.DBCollection; DB db = mongo.getDB mongo.getDB("test"); DBCollection collection = db.getCollection("foo"); db.getCollection codecentric AG
  • 11. Java Driver: Documents import com.mongodb.BasicDBObject com.mongodb.BasicDBObject; import com.mongodb.DBObject com.mongodb.DBObject; // insert document DBObject doc = new BasicDBObject(); doc.put("date", new Date()); doc.put("i", 42); collection.insert(doc doc); codecentric AG
  • 12. Java Driver: Queries import com.mongodb.DBCursor com.mongodb.DBCursor; DBCursor cursor; cursor = collection.find(); // all documents (); // documents w/ {i: 42} cursor = collection.find( ( new BasicDBObject("i i", 42) ); document = cursor.next(); (); ... codecentric AG
  • 13. Java Driver: Order Use Case DB db = mongo.getDB("test"); DBCollection collection = db.getCollection("order" "order"); DBObject order; List<DBObject> items = new ArrayList<DBObject>(); >(); DBObject item; // order order = new BasicDBObject(); order.put("date", new Date()); order.put("custInfo" , "Tobias Trelle"); order.put("items", items); // items item = new BasicDBObject(); item.put("quantity", 1); item.put("price", 47.11); item.put("desc", "Item #1"); items.add(item); item = new BasicDBObject(); item.put("quantity", 2); item.put("price", 42.0); item.put("desc", "Item #2"); items.add(item); collection.insert(order); codecentric AG
  • 14. Spring Data MongoDB codecentric AG
  • 15. Spring Data MongoDB – Fact Sheet Vendor VMware / SpringSource License Apache License Version 2.0 License, Documentation http://www.springsource.org/spring-data/mongodb http://www.springsource.org/spring Main Features • Repository Support • Object/Document Mapping Document • Templating codecentric AG
  • 16. Spring Data Common patterns for RDBMS and NoSQL data stores Spring Data CrudRepository PagingAndSortingRepository Spring Data Spring Data Spring Data Spring Data JPA MongoDB Neo4j … JpaRepository MongoRepository GraphRepository MongoTemplate Neo4jTemplate Embedded REST JPA Mongo Java Driver JDBC RDBMS MongoDB Neo4j … Quelle: http://www.infoq.com/articles/spring http://www.infoq.com/articles/spring-data-intro codecentric AG
  • 17. Spring Data MongoDB Templating − Resource abstraction − Configure connections to mongod / mongos node(s) − Collection lifecycle ( create, drop) − Map/Reduce / Aggregation Object Mapping − Annotation based: @Document, @Field, @Index etc. , − Classes are mapped to collections, Java Objects to documents , Repository Support − Queries are derived from methods signatures − Geospatial Queries codecentric AG
  • 18. Spring Data MongoDB Template Configuration <!-- Connection to MongoDB server -- --> <mongo:db-factory host="localhost" port port="27017" dbname="test" /> <!-- MongoDB Template --> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory ref="mongoDbFactory"/> mongoDbFactory" </bean> Usage @Autowired MongoTemplate template; template.indexOps(Location.class).ensureIndex ensureIndex( new GeospatialIndex("position") ); ) codecentric AG
  • 19. Spring Data MongoDB: Object Mapping public class Order { @Id private String id; private Date date; @Field("custInfo") private String customerInfo; List<Item> items; ... } public class Item { private int quantity; private double price; @Field("desc") private String description description; ... } codecentric AG
  • 20. Spring Data MongoDB: Repository Support public interface OrderRepository extends MongoRepository<Order, String> { <Order, findByItemsQuantity(int quantity); List<Order> findByItemsQuantity findByItemsPriceGreaterThan(double price); List<Order> findByItemsPriceGreaterThan } codecentric AG
  • 21. Spring Data MongoDB: Repository Support − Main Concept: use the signature of a method to derive the query (at runtime) − Base Implementations / abstractions for − CRUD operations − Paging − Sorting codecentric AG
  • 22. Spring Data MongoDB: Additional Goodies − Map/Reduce / Aggregation framework − Index Management − Support for GridFS − Geopspatial indexes / queries − Optimistic Locking codecentric AG
  • 24. Hibernate OGM MongoDB – Fact Sheet Vendor JBoss / Redhat License GNU LGPL, Version 2.1 , Documentation http://www.hibernate.org/subprojects/ogm.html Main Features • JPA API (Subset Subset) • JPQL Query Language codecentric AG
  • 25. Hibernate OGM − Implements JPA API (subset) − JP-QL query are translated to native QL datastore queries − Supports Infinispan, EhCache, MongoDB , codecentric AG
  • 26. Hibernate OGM Architecture Source: http://docs.jboss.org/hibernate/ogm/4.0/reference /en-US/html/ogm-architecture.html#d0e409 codecentric AG
  • 27. Hibernate OGM MongoDB: Configuration <persistence version="2.0" …> <persistence-unit name="primary"> <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence HibernateOgmPersistence</provider> <class>hibernate.Order</class> <class>hibernate.Item</class> <properties> <property name="hibernate.ogm.datastore.provider hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider" "org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/> <property name="hibernate.ogm.mongodb.database value=„odm"/> hibernate.ogm.mongodb.database" <property name="hibernate.ogm.mongodb.host value=„localhost"/> hibernate.ogm.mongodb.host" <property name="hibernate.ogm.mongodb.port value=„27017"/> hibernate.ogm.mongodb.port" </properties> </persistence-unit> </persistence> codecentric AG
  • 28. Hibernate OGM MongoDB: Object Mapping @Entity @NamedQuery( name="byItemsQuantity", query = "SELECT o FROM Order o JOIN o.items i WHERE i.quantity = :quantity" ) public class Order { @GeneratedValue(generator = "uuid") @GenericGenerator(name = "uuid", strategy = "uuid2" "uuid2") @Id private String id; private Date date; @Column(name = "custInfo") private String customerInfo customerInfo; @ElementCollection private List<Item> items; codecentric AG
  • 29. Hibernate OGM MongoDB: Object Mapping @Embeddable public class Item { private int quantity; private double price; @Column(name="desc") private String description description; ... codecentric AG
  • 30. Hibernate OGM: Summary − Very early beta − Only persist / merge / remove nly − No query support (yet) o − Uses relational API codecentric AG
  • 33. Morphia – Fact Sheet Developer Scott Hernandez, James Green License Apache License Version 2.0 License, Documentation https://github.com/jmkgreen/morphia/wiki/Overview Main Features • Object/Document Mapping Document • Custom Query API • DAO support codecentric AG
  • 34. Morphia: Object Mapping public class Order { @Id private ObjectId id; private Date date; @Property("custInfo") private String customerInfo; @Embedded List<Item> items; ... } public class Item { private int quantity; private double price; @Property("desc") private String description description; ... } codecentric AG
  • 35. Morphia: Queries public class OrderDao extends BasicDAO BasicDAO<Order, ObjectId> { List<Order> findByItemsQuantity(int quantity) { return find( createQuery().filter("items.quantity items.quantity", quantity)) .asList(); } findByItemsPriceGreaterThan(double price) { List<Order> findByItemsPriceGreaterThan return find( createQuery().field("items.price items.price").greaterThan(price) ) .asList(); } … } codecentric AG
  • 36. Morphia: Custom query syntax – why? Morphia Mongo Query = $eq $ !=, <> $neq $ >, <, >=,<= $gt, $ $lt, $gte, $lte in, nin $in, $ $nin elem $elemMatch $ … …. codecentric AG
  • 37. Judge yourself … Spring Data MongoDB https://github.com/ttrelle/spring-data-examples https://github.com/ttrelle/spring Hibernate OGM MongoDB https://github.com/ttrelle/hibernate github.com/ttrelle/hibernate-ogm-examples Morphia https://github.com/ttrelle/morphia github.com/ttrelle/morphia-mongodb-examples codecentric AG
  • 38. Which one should I use? High Abstraction Spring Data MongoDB JPA Hibernate OGM Morphia Enterprise Custom Standard API MongoDB Java JDBC Driver Low Abstraction codecentric AG
  • 39. German MongoDB User Groups (MUGs) MUG Düsseldorf MUG Berlin https://www.xing.com/net/mongodb-dus http://www.meetup.com/MUGBerlin/ @MongoDUS @MUGBerlin MUG Frankfurt/Main Hamburg MUG https://www.xing.com/net/mongodb-ffm https://www.xing.com/net/mugh @MongoFFM MUG München http://www.meetup.com/Muenchen-MongoDB MongoDB-User-Group/ @mongomuc codecentric AG
  • 40. QUESTIONS? Tobias Trelle codecentric AG Merscheider Str. 1 42699 Solingen tel +49 (0) 212.233628.47 fax +49 (0) 212.233628.79 mail Tobias.Trelle@codecentric.de twitter @tobiastrelle www.codecentric.de blog.codecentric.de/en/author/tobias-trelle trelle www.xing.com/net/mongodb-dus codecentric AG