krishna
krishna

Reputation: 499

Difference between Configuring MongoDB using Annotations and Hibernate OGM

Can anyone please clear me whether using MongoDB Annotations or implementing MongoDB using Hibernate will be Consistent.

Upvotes: 0

Views: 147

Answers (1)

Davide D'Alto
Davide D'Alto

Reputation: 8206

Disclamair: I'm one of the Hibernate OGM developers so I'll try to give the Hibernate OGM side of things.

Not sure what you mean by consistent but I'll try to answer.

Hibernate OGM provides Java Persistence (JPA) support for NoSQL solutions. It reuses Hibernate ORM’s engine but persists entities into a NoSQL datastore instead of a relational database.

There are several benefits in this approach:

  • It's easier to start on a project if you are already familiar with JPA or Hibernate ORM and less familiar with the NoSQL world. Hibernate OGM will be already capable of applying best practices and optimizations based on the mapping.

  • Portability, you will be able to switch from MongoDB to another datastore (not limited to NoSQL) changing only the configuration properties. If an existing application uses Hibernate ORM to connect to the DB, it will be now able to connect to a NoSQL datastore as well. it

  • Tools, because the API is the same as Hibernate ORM, you will be able to reuse existing tools or libraries.

  • It will be able to make some optimizations under the hood, like grouping the operations and making less calls to the datastore.

While the main goal is to provide a JPA implementation, you will also be able to execute native queries and we aim to provide ways to access specific DB features if needed.

The main drawback is that some of the concepts of JPA are not easily mapped to the NoSQL world: transactions for example. While you will have access to transaction demarcation method, you won't be able to rollback on datastores that don't support transactions natively (transactions in this case will be used to group operations and try to optimize the number of calls to the db).

Also, if your dataset is by nature non domain model centric, then Hibernate OGM is not for you.

Upvotes: 1

Related Questions