Playing with Hibernate OGM

While preparing for our server meeting played a bit with Hibernate OGM. It looks like an attempt to access NoSQL storages in the uniform way. I took JPA approach and tested three NoSQL storages:

  1. MongoDB
  2. CouchDB
  3. Neo4J

Source code is available on Github. So I took the following entities to test:

public class UserProfile implements Serializable {
@Column(length = 32)
private String name;

private byte[] password;

@Basic(fetch = FetchType.LAZY)
private byte[] avatar;

@OneToMany(orphanRemoval = true)
private List<AccelerometerRecord> records;

private Address address;


public class Address implements Serializable {
@Column private String city;
@Column private String country;


public class AccelerometerRecord implements Serializable {
private long id;

@ManyToOne(optional = false)
private UserProfile userProfile;


So the test code covers:

  1. Embedded objects
  2. Relations
  3. Blobs
  4. Byte arrays
  5. JPQL queries
  6. Native queries

You can easily reproduce results on your own running the code. Let me summarize the state of support of the tested NoSQL storages.


Support is very good. Everything works as it should. All the features I’ve checked are supported. I guess it was the first reference implementation and it got much more love from the developers. I guess migration from RDBMS with JPA to MongoDB with JPA should go pretty seamlessly if you’re stuck with JPQL


Support is marked as experimental. As yes. it’s really experimental to the extent that it’s not very usable. You can do usual CRUD with EntityManager and even execute simple queries but:

  1. Hibernate-search and lucene is used for search So you have to mark entites andproperties you’re going to use in search with Indexed/IndexedEmbedded annotations explicitly.
  2. Queries with embedded objects crash both in native and JPQL variant with NullPointerException
  3. Reading serialized byte array causes “java.lang.IllegalArgumentException: Can not set [B field by.defascat.hibernate.ogm.test.entity.UserProfile.password to java.lang.String”

So the implementation is in the very early stages and you definitely don’t gonna use it in production.


Support for Neo4J is somewhere in between Mongo and CouchDB. Regularly it behaves quite normally however you need to pay attention to these things:

  1. Queries with embedded objects do not work for JPQL
  2. Neo4J implementation requires every single query including simple select to be wrapped into transaction. That’s not the case with MongoDB/CouchDB where only insert/update/delete require an active transaction
  3. Neo4J uses 3.6 version of Lucene which conflicts with CouchDB OGM implementation that requires 4.10 version of Lucene. You need to be aware on what things are in your classpath already.


You can already use all MongoDB/Neo4J if everything you do is simple CRUD and executing simple queries. However I would evaluate only MongoDB implementation if I had a chance to use it on the real project. However the idea of Hibernate OGM  is perfect and I’m looking forward to use it in my future projects.

This entry was posted in Development and tagged , , , . Bookmark the permalink.

1 Response to Playing with Hibernate OGM

  1. Pingback: Interesting Java related Links. Week 7, 2015 | My Technical Life

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s