When to use MongoDB Driver/Morphia over Hibernate

1.9k views Asked by At

I am currently working with MongoDB and Java and I have to decide if I use MongoDB's Driver, Morphia or Hibernate. Can anyone tell me what the advantages and disadvantages of Hibernate, MongoDB's Driver and Morphia are? And in what situation should I use which? A small example would also be nice, but is not really necessary.

Thanks!

2

There are 2 answers

0
Dev On

Using a native driver :

It is always better if you have time to learn that driver. Now coming to Mongo-Java-Driver it is quite simple to use. Initially terms like BasicDBObject, BSONObject may sound odd to you. After some time, you will find it comfortable. You can start with this quick tour to Mongo Java Driver.

Using ORM tool :

ORM tools like spring data, Kundera, Morphia use these native drivers internally. These makes it simple and comfortable to the user with some overhead in terms of performance sometimes.

So, it's up to you if you have time to explore go for Mongo-Java-Driver. otherwise, go for any ORM tool according to your use case. Not familiar with morphia. I guess hibernate is for RDBMS only. Hibernate OGM is for NoSQL databases.

Edit: Kundera is no longer maintained. Please use alternatives.


For example, You can use Kundera if you want to query in JPA way like in RDBMS databases. It's an open-source object mapper for NoSQL databases supporting MongoDB, Cassandra, HBase, ONS, etc. It takes query in JPA format like

 select p from Person p where p.salary > 20000
0
afarag On

I think native is better, It seems ORM with Mongodb contains restrictions, (e.g, using eclipse-link you could not directly persist Map)