Over a million developers have joined DZone.

From Hibernate to MongoDB, Part 1

DZone's Guide to

From Hibernate to MongoDB, Part 1

· Java Zone ·
Free Resource

Java-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.

This is not necessarily eclipse related, but it comes from my eclipse project that I recently ported to RAP and now I plan to go multi-tenant with it.

This is not my first attempt in this direction, but I have a working proof of concept for changing my persistence layer from Hibernate/Hibernate Search to MongoDB.

I have about 80 domain classes and a bunch of handmade custom DAOs that are mostly based on the JPA. After playing with OrientDB (I stopped that because of "delete-orphan") this weekend I made an attempt with the datanucleus MongoDB storage engine. To replace Hibernate Search, I decided to go with ElasticSearch, which seems to be a straightforward way to build a multi-tenant index.

At first, I struggled with some classloading issues.  The datanucleus enhanced classes need a dependency on the JDO API at runtime. Then one major all-solution refactoring to use the MongoDB string-based id on all my entities. I guess that took most of the time. I also changed many dependency relations to embedded types so that I could get the performance benefits that MongoDB promises.

Before MongoDB I had load times for a single object graph (Hibernate/SQL Server) from 3 to 4 seconds (yes one entity, you now know why I have to change that) and with MongoDB and all the embedded collections you can hardly notice load time.

It's just that the relational model is not suited for complex object graphs. Even with massive parallel processing on a SQL Server cluster I had processing times around 10 minutes for 50k objects. I do not have values on that for Mongo (need an importer first), but I guess it will work out.

I still have some exceptions and need to refine the ElasticSearch integration, but overall I worked some 15 hours on it and now I at least have proof that it's doable.

Connect any Java based application to your SaaS data.  Over 100+ Java-based data source connectors.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}