{"id":712,"date":"2011-11-03T19:27:00","date_gmt":"2011-11-03T19:27:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/using-mongodb-with-morphia.html"},"modified":"2012-10-21T20:43:56","modified_gmt":"2012-10-21T20:43:56","slug":"using-mongodb-with-morphia","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html","title":{"rendered":"Using MongoDB with Morphia"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">In the past few years, <a href=\"http:\/\/en.wikipedia.org\/wiki\/NoSQL_%28concept%29\">NoSQL<\/a> databases like CouchDB, Cassandra and MongoDB have gained some popularity for applications that don\u2019t require the semantics and overhead of running a traditional RDBMS. I won\u2019t get into the design decisions to go into choosing a NoSQL database as others have done a good enough job already, but I will relate my experience with MongoDB and some tricks on using it effectively in Java.<\/p>\n<p>I recently have had a chance to work with <a href=\"http:\/\/www.mongodb.org\/\">MongoDB<\/a> (as in humongoous), which is a document-oriented database written in C++. It is ideal for storing documents which may vary in structure, and it uses a format similar to JSON, which means it supports similar data types and structures as JSON. It provides a rich yet simple query language and still allows us to index key fields for fast retrieval. Documents are stored in collections which effectively limit the scope of a query, but there is really no limitation on the types of heterogeneous data that you can store in a collection. The <a href=\"http:\/\/www.mongodb.org\/display\/DOCS\/Home\">MongoDB site<\/a> has decent docs if you need to learn the basics of MongoDB.<\/p>\n<p><span style=\"font-weight: bold\">MongoDB in Java<\/span><\/p>\n<p>The Mongo Java driver basically exposes all documents as key-value pairs exposed as map, and lists of values. This means that if we have to store or retrieve documents in Java, we will have to do some mapping of our POJOs to that map interface. Below is an example of the type of code we would normally have to write to save a document to MongoDB from Java:<\/p>\n<pre class=\"brush:java\">BasicDBObject doc = new BasicDBObject();\r\n\r\ndoc.put(\"user\", \"carfey\");\r\n\r\nBasicDBObject post1 = new BasicDBObject();\r\npost1.put(\"subject\", \"spam &amp; eggs\");\r\npost1.put(\"message\", \"first!\");\r\n\r\nBasicDBObject post2 = new BasicDBObject();\r\npost2.put(\"subject\", \"sorry about the spam\");\r\n\r\ndoc.put(\"posts\", Arrays.asList(post1, post2));\r\n\r\ncoll.insert(doc);\r\n<\/pre>\n<p>This is fine for some use cases, but for others, it would be better to have a library to do the grunt work for us.<\/p>\n<p><span style=\"font-weight: bold\">Enter Morphia<\/span><\/p>\n<p><a href=\"http:\/\/code.google.com\/p\/morphia\/\">Morphia<\/a> is a Java library which acts sort of like an ORM for MongoDB \u2013 it allows us to seamlessly map Java objects to the MongoDB datastore. It uses annotations to indicate which collection a class is stored in, and even supports polymorphic collections. One of the nicest features is that it can be used to automatically index your collections based on your collection- or property-level annotations. This greatly simplifies deployment and rolling out changes.<\/p>\n<p>I mentioned polymorphic storage of multiple types in the same collection. This can help us map varying document structures and acts somewhat like a <a href=\"http:\/\/docs.jboss.org\/hibernate\/core\/3.3\/reference\/en\/html\/mapping.html#mapping-declaration-discriminator\">discriminator<\/a> in something like Hibernate.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Here\u2019s an example of how to define entities which will support polymorphic storage and querying. The Return class is a child of Order and references the same collection-name. Morphia will automatically handle the polymorphism when querying or storing data. You would pretty much do the same thing for annotating collections that aren\u2019t polymorphic, but you wouldn\u2019t have multiple classes using the same collection name.<\/p>\n<p><span style=\"font-weight: bold\">Note:<\/span> This isn\u2019t really an example of the type of data I would recommend storing in MongoDB since it is more suited to a traditional RDBMS, but it demonstrates the principles nicely.<\/p>\n<pre class=\"brush:java\">@Entity(\"orders\") \/\/ store in the orders collection\r\n@Indexes({ @Index(\"-createdDate, cancelled\") }) \/\/ multi-column index\r\npublic class Order {\r\n    @Id private ObjectId id; \/\/ always required\r\n\r\n    @Indexed\r\n    private String orderId;\r\n\r\n    @Embedded \/\/ let's us embed a complex object\r\n    private Person person;\r\n    @Embedded\r\n    private List&lt;Item&gt; items;\r\n\r\n    private Date createdDate;\r\n    private boolean cancelled;\r\n\r\n    \/\/ .. getters and setters aren't strictly required\r\n    \/\/ for mapping, but they would be here\r\n}\r\n\r\n@Entity(\"orders\") \/\/ note the same collection name\r\npublic class Return extends Order {\r\n    \/\/ maintain legacy name but name it nicely in mongodb\r\n    @Indexed\r\n    @Property(\"rmaNumber\") private String rma;\r\n    private Date approvedDate;\r\n    private Date returnDate;\r\n}\r\n<\/pre>\n<p>Now, below I will demonstrate how to query those polymorphic instances. Note that we don\u2019t have to do anything special when storing the data. MongoDB stores a className attribute along with the document so it can support polymorphic fetches and queries. Following the example above, I can query for all order types by doing the following:<\/p>\n<pre class=\"brush:java\">\/\/ ds is a Datastore instance\r\nQuery&lt;Order&gt; q = ds.createQuery(Order.class).filter(\"createdDate &gt;=\", date);\r\nList&lt;Order&gt; ordersAndReturns = q.asList();\r\n\r\n\/\/ and returns only\r\nQuery&lt;Return&gt; rq = ds.createQuery(Return.class).filter(\"createdDate &gt;=\", date);\r\nList&lt;Return&gt; returnsOnly = rq.asList();\r\n<\/pre>\n<p>If I only want to query plain orders, I would have to use a className filter as follows. This allows us to effectively disable the polymorphic behaviour and limit results to a single target type.<\/p>\n<pre class=\"brush:java\">Query&lt;Order&gt; q = ds.createQuery(Order.class)\r\n    .filter(\"createdDate &gt;=\", cutOffDate)\r\n    .filter(\"className\", Order.class.getName());\r\n\r\nList&lt;Order&gt; ordersOnly = q.asList();\r\n<\/pre>\n<p>Morphia currently uses the className attribute to filter results, but at some point in the future is likely to use a discriminator column, in which case you may have to filter on that value instead.<\/p>\n<p><span style=\"font-weight: bold\">Note:<\/span> At some point during startup of your application, you need to register your mapped classes so they can be used by Morphia. See here for <a href=\"http:\/\/code.google.com\/docreader\/#p=morphia&amp;s=morphia&amp;t=Datastore\">full details<\/a>. A quick example is below.<\/p>\n<pre class=\"brush:java\">Morphia m = ...\r\nDatastore ds = ...\r\n\r\nm.map(MyEntity.class);\r\nds.ensureIndexes(); \/\/creates all defined with @Indexed\r\nds.ensureCaps(); \/\/creates all collections for @Entity(cap=@CappedAt(...))\r\n<\/pre>\n<p><span style=\"font-weight: bold\">Problems with Varying Structure in Documents<\/span><\/p>\n<p>One of the nice features of document-oriented storage in MongoDB is that it allows you to store documents with different structure in the same collection, but still perform structured queries and index values to get good performance.<\/p>\n<p>Morphia unfortunately doesn\u2019t really like this as it is meant to map all stored attributes to known POJO fields. There are currently two ways I\u2019ve found that let us deal with this.<\/p>\n<p>The first is disabling validation on queries. This will mean that values which exist in the datastore but can\u2019t be mapped to our POJOs will be dropped rather than blowing up:<\/p>\n<pre class=\"brush:java\">\/\/ drop unmapped fields quietly\r\nQuery&lt;Order&gt; q = ds.createQuery(Order.class).disableValidation();\r\n<\/pre>\n<p>The other option is to store all unstructured content under a single bucket element using a Map. This could contain any basic types supported by the MongoDB driver including Lists and Maps, but no complex objects unless you have registered converters with Morphia (e.g. morphia.getMapper().getConverters().addConverter(new MyCustomTypeConverter()) . <\/p>\n<pre class=\"brush:java\">@Entity(\"orders\")\r\npublic class Order {\r\n    \/\/ .. our base attributes here\r\n    private Map&lt;String, Object&gt; attributes; \/\/ bucket for everything else (\r\n}\r\n<\/pre>\n<p>Note that Morphia may complain on startup that it can\u2019t validate the field (since the generics declaration is not strict), but as of the current release version (0.99), it will work with no problem and store any attributes normally and retrieve them as maps and lists of values.<\/p>\n<p>Note: When it populates a loosely-typed map from a retrieved document, it will use the basic MongoDB Java driver types BasicDBObject and BasicDBList. These implement Map and List respectively, so they will work pretty much as you expect, except that they will not be equals() to any input maps or lists you may have stored, even if the structure and content appear to be equal. If you want to avoid this, you can use the @PostLoad annotation to annotate a method which can perform normalization to JDK maps and lists after the document is loaded. I personally did this to ensure we always see a consistent view of MongoDB documents whether they are pulled from a collection or not yet persisted. <\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/www.carfey.com\/blog\/using-mongodb-with-morphia\/\">Using MongoDB with Morphia<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a>s at the <a href=\"http:\/\/www.carfey.com\/blog\/\">Carfey Software blog<\/a>. <\/p>\n<p><strong><i>Related Articles :<\/i><\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2010\/12\/cassandra-vs-mongodb-vs-couchdb-vs.html\">Cassandra vs MongoDB vs CouchDB vs Redis vs Riak vs HBase comparison<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/03\/java-code-geeks-andygene-web-archetype.html\">Java Code Geeks Andygene Web Archetype<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/p\/java-tutorials.html\">Java Tutorials and Android Tutorials list<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/top-97-things-every-programmer-or.html\">The top 9+7 things every programmer or architect should know<\/a> <\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In the past few years, NoSQL databases like CouchDB, Cassandra and MongoDB have gained some popularity for applications that don\u2019t require the semantics and overhead of running a traditional RDBMS. I won\u2019t get into the design decisions to go into choosing a NoSQL database as others have done a good enough job already, but I &hellip;<\/p>\n","protected":false},"author":59,"featured_media":187,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[112,318],"class_list":["post-712","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-mongodb","tag-morphia"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using MongoDB with Morphia - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In the past few years, NoSQL databases like CouchDB, Cassandra and MongoDB have gained some popularity for applications that don\u2019t require the semantics\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using MongoDB with Morphia - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In the past few years, NoSQL databases like CouchDB, Cassandra and MongoDB have gained some popularity for applications that don\u2019t require the semantics\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2011-11-03T19:27:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T20:43:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Craig Flichel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Craig Flichel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html\"},\"author\":{\"name\":\"Craig Flichel\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c1bcd58320330b548e07d846510f9460\"},\"headline\":\"Using MongoDB with Morphia\",\"datePublished\":\"2011-11-03T19:27:00+00:00\",\"dateModified\":\"2012-10-21T20:43:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html\"},\"wordCount\":1032,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mongodb-logo.jpg\",\"keywords\":[\"MongoDB\",\"Morphia\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html\",\"name\":\"Using MongoDB with Morphia - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mongodb-logo.jpg\",\"datePublished\":\"2011-11-03T19:27:00+00:00\",\"dateModified\":\"2012-10-21T20:43:56+00:00\",\"description\":\"In the past few years, NoSQL databases like CouchDB, Cassandra and MongoDB have gained some popularity for applications that don\u2019t require the semantics\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mongodb-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/mongodb-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/using-mongodb-with-morphia.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Using MongoDB with Morphia\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c1bcd58320330b548e07d846510f9460\",\"name\":\"Craig Flichel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f7ada05eac86c369123683747aa5f714e262e52d4af354efe8aba14f76075dc4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f7ada05eac86c369123683747aa5f714e262e52d4af354efe8aba14f76075dc4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f7ada05eac86c369123683747aa5f714e262e52d4af354efe8aba14f76075dc4?s=96&d=mm&r=g\",\"caption\":\"Craig Flichel\"},\"sameAs\":[\"http:\\\/\\\/www.carfey.com\\\/blog\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Craig-Flichel\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using MongoDB with Morphia - Java Code Geeks","description":"In the past few years, NoSQL databases like CouchDB, Cassandra and MongoDB have gained some popularity for applications that don\u2019t require the semantics","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html","og_locale":"en_US","og_type":"article","og_title":"Using MongoDB with Morphia - Java Code Geeks","og_description":"In the past few years, NoSQL databases like CouchDB, Cassandra and MongoDB have gained some popularity for applications that don\u2019t require the semantics","og_url":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-11-03T19:27:00+00:00","article_modified_time":"2012-10-21T20:43:56+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg","type":"image\/jpeg"}],"author":"Craig Flichel","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Craig Flichel","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html"},"author":{"name":"Craig Flichel","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c1bcd58320330b548e07d846510f9460"},"headline":"Using MongoDB with Morphia","datePublished":"2011-11-03T19:27:00+00:00","dateModified":"2012-10-21T20:43:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html"},"wordCount":1032,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg","keywords":["MongoDB","Morphia"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html","url":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html","name":"Using MongoDB with Morphia - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg","datePublished":"2011-11-03T19:27:00+00:00","dateModified":"2012-10-21T20:43:56+00:00","description":"In the past few years, NoSQL databases like CouchDB, Cassandra and MongoDB have gained some popularity for applications that don\u2019t require the semantics","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/mongodb-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/using-mongodb-with-morphia.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Using MongoDB with Morphia"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c1bcd58320330b548e07d846510f9460","name":"Craig Flichel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f7ada05eac86c369123683747aa5f714e262e52d4af354efe8aba14f76075dc4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f7ada05eac86c369123683747aa5f714e262e52d4af354efe8aba14f76075dc4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f7ada05eac86c369123683747aa5f714e262e52d4af354efe8aba14f76075dc4?s=96&d=mm&r=g","caption":"Craig Flichel"},"sameAs":["http:\/\/www.carfey.com\/blog\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Craig-Flichel"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/59"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=712"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/712\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/187"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}