I am trying to migrate a hibernate/mysql project to mongodb. Does hibernate support migration to mongodb? If so, how are ORM mappings like one-to-one or one-to-many relationships translated?
How to use Hibernate OGM with MongoDB? To get started with Hibernate MongoDB, you first need to build the OGM from Source via GitBug. To include OGM in your Hibernate MongoDB project, just include one more dependency in your list of dependencies. Next, to define the persistence unit, create a META-INF/persistence.
Yes, DataNucleus JPA allows it, as well as to many other databases.
Hibernate supports relational databases, like MySQL, PostgreSQL, Oracle, DB2 and SQL Server. MongoDB, however, isn't a relational database, it's a document database. The differences are quite huge:
So, to answer your question, Hibernate doesn't support MongoDB and I think chances are close to zero that it ever will.
However, there are ORM implementations for Java / MongoDB, for example MJORM.
However, since these are two completely different points-of-view to database organisation, there is no simple process to migrate. At the very least it will include re-thinking your database design. So it may be worth to re-consider the migration, and see whether or not it is actually needed. In the end, MongoDB is not a drop-in replacement for a relational database, since it isn't a relational database. See the following links for some discussion on the two types of databases:
UPDATE Regarding Hibernate OGM
You can probably use Hibernate OGM. IMHO, there are two drawbacks:
Also it's worth to look at Morphia https://github.com/mongodb/morphia. It's basically Java ORM library similar to Hibernate but does not support JPA annotations.
Your best choice should be to go through Spring Data MongoDB
It's quiet straight forward to implement.
Have look there: http://www.mkyong.com/mongodb/spring-data-mongodb-hello-world-example/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With