SlideShare ist ein Scribd-Unternehmen logo
1 von 40
MongoDB Berlin 2013:
Java Persistence Frameworks for MongoDB


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

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

                 -   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 Driver

          Spring Data MongoDB

          Morphia

          Hibernate OGM
codecentric AG
Use Case




db.order.find( {"items.quantity": ? } )

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

codecentric AG
MongoDB Java Driver


      One JAR w/o further dependencies:

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

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



codecentric AG
Java Driver: Connect to MongoDB

import com.mongodb.MongoClient;

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

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

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

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

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

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

codecentric AG
Java Driver: Documents

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

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

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

import com.mongodb.DBCursor;

DBCursor cursor;

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

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

document = cursor.next();
...
codecentric AG
Java Driver: Order Use Case
DB db = mongo.getDB("test");
DBCollection collection = db.getCollection("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
  Documentation   http://www.springsource.org/spring-data/mongodb
  Main Features   • Repository Support
                  • Object/Document Mapping
                  • 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-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="27017" dbname="test" />


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

Usage

     @Autowired MongoTemplate template;

     template.indexOps(Location.class).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;
  ...
}


codecentric AG
Spring Data MongoDB: Repository Support

public interface OrderRepository extends
  MongoRepository<Order, String> {

     List<Order> findByItemsQuantity(int quantity);

     List<Order> findByItemsPriceGreaterThan(double price);

}




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)
                  • JPQL Query Language




codecentric AG
Hibernate OGM


         Implements JPA API (subset)

       JP-QL query are translated to native
      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</provider>
         <class>hibernate.Order</class>
         <class>hibernate.Item</class>
         <properties>
                 <property name="hibernate.ogm.datastore.provider"
                 value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
                 <property name="hibernate.ogm.mongodb.database" value=„odm"/>
                 <property name="hibernate.ogm.mongodb.host" value=„localhost"/>
                 <property name="hibernate.ogm.mongodb.port" value=„27017"/>
         </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")
      @Id private String id;


      private Date date;


      @Column(name = "custInfo") private String 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;
      ...




codecentric AG
Hibernate OGM: Summary


         Very early beta

         Only persist / merge / remove

         No query support (yet)

         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
  Documentation   https://github.com/jmkgreen/morphia/wiki/Overview
  Main Features   • Object/Document Mapping
                  • 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;
      ...
}


codecentric AG
Morphia: Queries

public class OrderDao extends BasicDAO<Order, ObjectId> {


      List<Order> findByItemsQuantity(int quantity) {
                 return
                 find( createQuery().filter("items.quantity", quantity))
                 .asList();
      }
      List<Order> findByItemsPriceGreaterThan(double price) {
                 return
                 find( createQuery().field("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

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

Morphia
https://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
MUG Düsseldorf

https://www.xing.com/net/mongodb-dus
@MongoDUS

14.03.2013
„Volltextsuche in MongoDB 2.4“




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
www.xing.com/net/mongodb-dus

codecentric AG

Weitere ähnliche Inhalte

Was ist angesagt?

Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDBScott Hernandez
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaScott Hernandez
 
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
 
Real World Application Performance with MongoDB
Real World Application Performance with MongoDBReal World Application Performance with MongoDB
Real World Application Performance with MongoDBMongoDB
 
Webinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and MorphiaWebinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and MorphiaMongoDB
 
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
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryAlexandre Morgaut
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Oliver Gierke
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSMongoDB
 
아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문NAVER D2
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningPuneet Behl
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDoug Green
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBUwe Printz
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?Trisha Gee
 
Introduction to Restkit
Introduction to RestkitIntroduction to Restkit
Introduction to Restkitpetertmarks
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkBack to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkMongoDB
 

Was ist angesagt? (19)

Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDB
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with Morphia
 
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
 
Real World Application Performance with MongoDB
Real World Application Performance with MongoDBReal World Application Performance with MongoDB
Real World Application Performance with MongoDB
 
Webinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and MorphiaWebinar: MongoDB Persistence with Java and Morphia
Webinar: MongoDB Persistence with Java and Morphia
 
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
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJS
 
아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and Drupal
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDB
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
 
Groovy.pptx
Groovy.pptxGroovy.pptx
Groovy.pptx
 
Introduction to Restkit
Introduction to RestkitIntroduction to Restkit
Introduction to Restkit
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkBack to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation Framework
 

Andere mochten auch

Java driver for mongo db
Java driver for mongo dbJava driver for mongo db
Java driver for mongo dbAbhay Pai
 
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
 
Mongo sf easy java persistence
Mongo sf   easy java persistenceMongo sf   easy java persistence
Mongo sf easy java persistenceScott Hernandez
 
What's new in the MongoDB Java Driver (2.5)?
What's new in the MongoDB Java Driver (2.5)?What's new in the MongoDB Java Driver (2.5)?
What's new in the MongoDB Java Driver (2.5)?Scott Hernandez
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo dbAmit Thakkar
 
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGMUsing JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGMPT.JUG
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for BeginnersEnoch Joshua
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010Eliot Horowitz
 

Andere mochten auch (13)

Java driver for mongo db
Java driver for mongo dbJava driver for mongo db
Java driver for mongo db
 
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...
 
Mongo sf easy java persistence
Mongo sf   easy java persistenceMongo sf   easy java persistence
Mongo sf easy java persistence
 
What's new in the MongoDB Java Driver (2.5)?
What's new in the MongoDB Java Driver (2.5)?What's new in the MongoDB Java Driver (2.5)?
What's new in the MongoDB Java Driver (2.5)?
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
 
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGMUsing JPA applications in the era of NoSQL: Introducing Hibernate OGM
Using JPA applications in the era of NoSQL: Introducing Hibernate OGM
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
Mongo db
Mongo dbMongo db
Mongo db
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
 

Ähnlich wie Java Persistence Frameworks for MongoDB

Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Kuo-Chun Su
 
Webinar: Building Your First App
Webinar: Building Your First AppWebinar: Building Your First App
Webinar: Building Your First AppMongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBChun-Kai Wang
 
MongoDB et Hadoop
MongoDB et HadoopMongoDB et Hadoop
MongoDB et HadoopMongoDB
 
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
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
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
 
Mongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongoDB
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introductionTse-Ching Ho
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)MongoSF
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB
 
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
 
using Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundryusing Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud FoundryJoshua Long
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Railsrfischer20
 

Ähnlich wie Java Persistence Frameworks for MongoDB (20)

Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Spring Data MongoDB 介紹
Spring Data MongoDB 介紹
 
Green dao
Green daoGreen dao
Green dao
 
ExSchema
ExSchemaExSchema
ExSchema
 
Webinar: Building Your First App
Webinar: Building Your First AppWebinar: Building Your First App
Webinar: Building Your First App
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
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
 
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
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
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
 
Mongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-final
 
mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt Groupe
 
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
 
using Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundryusing Spring and MongoDB on Cloud Foundry
using Spring and MongoDB on Cloud Foundry
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
 
Grails 101
Grails 101Grails 101
Grails 101
 

Mehr von Tobias Trelle

TDD mit JUnit und Mockito
TDD mit JUnit und MockitoTDD mit JUnit und Mockito
TDD mit JUnit und MockitoTobias Trelle
 
NoSQL - Einführung in Graphen-Datenbanken mit Neo4j
NoSQL - Einführung in Graphen-Datenbanken mit Neo4jNoSQL - Einführung in Graphen-Datenbanken mit Neo4j
NoSQL - Einführung in Graphen-Datenbanken mit Neo4jTobias Trelle
 
Einführung in NoSQL-Datenbanken
Einführung in NoSQL-DatenbankenEinführung in NoSQL-Datenbanken
Einführung in NoSQL-DatenbankenTobias Trelle
 
MongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwaltenMongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwaltenTobias Trelle
 
Test Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTest Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTobias Trelle
 
Morphia, Spring Data & Co
Morphia, Spring Data & CoMorphia, Spring Data & Co
Morphia, Spring Data & CoTobias Trelle
 
An introduction to MongoDB and Ruby
An introduction to MongoDB and RubyAn introduction to MongoDB and Ruby
An introduction to MongoDB and RubyTobias Trelle
 
OOP 2013: Praktische Einführung in MongoDB
OOP 2013: Praktische Einführung in MongoDBOOP 2013: Praktische Einführung in MongoDB
OOP 2013: Praktische Einführung in MongoDBTobias Trelle
 
MongoDB Munich 2012: Spring Data MongoDB
MongoDB Munich 2012: Spring Data MongoDBMongoDB Munich 2012: Spring Data MongoDB
MongoDB Munich 2012: Spring Data MongoDBTobias Trelle
 
MongoDB Live Hacking
MongoDB Live HackingMongoDB Live Hacking
MongoDB Live HackingTobias Trelle
 

Mehr von Tobias Trelle (11)

TDD mit JUnit und Mockito
TDD mit JUnit und MockitoTDD mit JUnit und Mockito
TDD mit JUnit und Mockito
 
NoSQL - Einführung in Graphen-Datenbanken mit Neo4j
NoSQL - Einführung in Graphen-Datenbanken mit Neo4jNoSQL - Einführung in Graphen-Datenbanken mit Neo4j
NoSQL - Einführung in Graphen-Datenbanken mit Neo4j
 
Einführung in NoSQL-Datenbanken
Einführung in NoSQL-DatenbankenEinführung in NoSQL-Datenbanken
Einführung in NoSQL-Datenbanken
 
MongoDB Einführung
MongoDB EinführungMongoDB Einführung
MongoDB Einführung
 
MongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwaltenMongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwalten
 
Test Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTest Automation for NoSQL Databases
Test Automation for NoSQL Databases
 
Morphia, Spring Data & Co
Morphia, Spring Data & CoMorphia, Spring Data & Co
Morphia, Spring Data & Co
 
An introduction to MongoDB and Ruby
An introduction to MongoDB and RubyAn introduction to MongoDB and Ruby
An introduction to MongoDB and Ruby
 
OOP 2013: Praktische Einführung in MongoDB
OOP 2013: Praktische Einführung in MongoDBOOP 2013: Praktische Einführung in MongoDB
OOP 2013: Praktische Einführung in MongoDB
 
MongoDB Munich 2012: Spring Data MongoDB
MongoDB Munich 2012: Spring Data MongoDBMongoDB Munich 2012: Spring Data MongoDB
MongoDB Munich 2012: Spring Data MongoDB
 
MongoDB Live Hacking
MongoDB Live HackingMongoDB Live Hacking
MongoDB Live Hacking
 

Kürzlich hochgeladen

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Kürzlich hochgeladen (20)

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

Java Persistence Frameworks for MongoDB

  • 1. MongoDB Berlin 2013: Java Persistence Frameworks for MongoDB Tobias.Trelle@codecentric.de / @tobiastrelle codecentric AG
  • 2. Tobias Trelle - Senior IT Consultant @ codecentric AG (official 10gen partner) - 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 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 codecentric AG
  • 8. MongoDB Java Driver One JAR w/o further dependencies: <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>2.10.0</version> </dependency> github: https://github.com/mongodb/mongo-java-driver codecentric AG
  • 9. Java Driver: Connect to MongoDB import com.mongodb.MongoClient; // Default: localhost:27017 mongo = new MongoClient(); // Sharding: mongos server mongo = new MongoClient("mongos01", 4711); // Replica set mongo = new MongoClient(Arrays.asList( new ServerAddress("replicant01", 10001), new ServerAddress("replicant02", 10002), new ServerAddress("replicant03", 10003) )); codecentric AG
  • 10. Java Driver: Database / Collection import com.mongodb.DB; import com.mongodb.DBCollection; DB db = mongo.getDB("test"); DBCollection collection = db.getCollection("foo"); codecentric AG
  • 11. Java Driver: Documents import com.mongodb.BasicDBObject; import com.mongodb.DBObject; // insert document DBObject doc = new BasicDBObject(); doc.put("date", new Date()); doc.put("i", 42); collection.insert(doc); codecentric AG
  • 12. Java Driver: Queries import com.mongodb.DBCursor; DBCursor cursor; cursor = collection.find(); // all documents // documents w/ {i: 42} cursor = collection.find( new BasicDBObject("i", 42) ); document = cursor.next(); ... codecentric AG
  • 13. Java Driver: Order Use Case DB db = mongo.getDB("test"); DBCollection collection = db.getCollection("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 Documentation http://www.springsource.org/spring-data/mongodb Main Features • Repository Support • Object/Document Mapping • 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-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="27017" dbname="test" /> <!-- MongoDB Template --> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/> </bean> Usage @Autowired MongoTemplate template; template.indexOps(Location.class).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; ... } codecentric AG
  • 20. Spring Data MongoDB: Repository Support public interface OrderRepository extends MongoRepository<Order, String> { List<Order> findByItemsQuantity(int quantity); List<Order> findByItemsPriceGreaterThan(double price); } 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) • JPQL Query Language codecentric AG
  • 25. Hibernate OGM Implements JPA API (subset) JP-QL query are translated to native datastore queries Supports Infinispan, EhCache, MongoDB codecentric AG
  • 27. Hibernate OGM MongoDB: Configuration <persistence version="2.0" …> <persistence-unit name="primary"> <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider> <class>hibernate.Order</class> <class>hibernate.Item</class> <properties> <property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/> <property name="hibernate.ogm.mongodb.database" value=„odm"/> <property name="hibernate.ogm.mongodb.host" value=„localhost"/> <property name="hibernate.ogm.mongodb.port" value=„27017"/> </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") @Id private String id; private Date date; @Column(name = "custInfo") private String 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; ... codecentric AG
  • 30. Hibernate OGM: Summary Very early beta Only persist / merge / remove No query support (yet) Uses relational API codecentric AG
  • 33. Morphia – Fact Sheet Developer Scott Hernandez, James Green License Apache License, Version 2.0 Documentation https://github.com/jmkgreen/morphia/wiki/Overview Main Features • Object/Document Mapping • 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; ... } codecentric AG
  • 35. Morphia: Queries public class OrderDao extends BasicDAO<Order, ObjectId> { List<Order> findByItemsQuantity(int quantity) { return find( createQuery().filter("items.quantity", quantity)) .asList(); } List<Order> findByItemsPriceGreaterThan(double price) { return find( createQuery().field("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 Hibernate OGM MongoDB https://github.com/ttrelle/hibernate-ogm-examples Morphia https://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
  • 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 www.xing.com/net/mongodb-dus codecentric AG