Should we use OGM/ORM like hibernate in java for Mongodb? [closed] Should we use OGM/ORM like hibernate in java for Mongodb? [closed] mongodb mongodb

Should we use OGM/ORM like hibernate in java for Mongodb? [closed]


Of course, ORMs are easy to use and many of them allow us to use SQL or JPQL for querying in a similar way like RDBMS but ORMs have their own limitation and yeah they will add a little bit of overhead too(in terms of performance). That's why using Native MongoDB Java Driver is preferred.

For NOSQL databases, choosing an ORM purely depends upon the use case. An ORM will map your table(Collection in the case of MongoDB) to an Entity Object. You added, you can keep a map in entity which will allow your design to become a little bit of schemaless. Most of the time our data is almost structured so ORMs can be used. But if you have completely versatile and unstructured data go for Java Driver. Check Mongo's documentation.

Also, there are other stable ORM tools like Kundera, Spring Data. You should explore them.

PS:

  • This answer is for ORMs vs native driver not on Hibernate ORM
  • I am a Kundera developer


I would recommend a OGM framework like Tinkerpop, or if you need something a bit higher level and more similar to Hibernate then consider Ferma. Ferma sits on top of Tinkerpop and uses annotations to define Java classes that resemble an Entity in JPA and Hibernate. The difference is Ferma and Tinkerpop is built specifically for graph databases rather than trying to stuff it into a framework designed for traditional Relational Databases.

One nice feature of Ferma and Tinkerpop is that while built for Graph Databases they still work on Relational Databases. There are several drivers for Tinkerpop that allow it to work on virtually every major Graph Database and Relational Database on the market. It can also use in-memory drivers that exist natively in Tinkerpop and therefore doesn't need to be backed by any database at all. Its an extremely flexible platform that has a lot of benefits when it comes to modular and flexible code.

For reference here is the description of the Ferma project.

The Ferma project was originally created as an alternative to the TinkerPop2 Frames project. Which at the time lacked features needed by the community, and its performance was cripplingly slow. Today Ferma is a robust framework that takes on a role similar to an Object-relational Model (ORM) library for traditional databases. Ferma is often referred to as a Object-graph Model (OGM) library, and maps Java objects to elements in a graph such as a Vertex or an Edge. In short it allows a schema to be defined using java interfaces and classes which provides a level of abstraction for interacting with the underlying graph.

And also the description of the Tinkerpop project.

Apache TinkerPop™ is a graph computing framework for both graph databases (OLTP) and graph analytic systems (OLAP).

Note: I am one of the author's of Ferma.