Reputation: 531
I'm looking for resources showing how to integrate MongoDB with Hibernate (preferably from within spring) so that I can switch between a RDBMS and a NoSql alternative: does anyone have experience doing this?
Upvotes: 47
Views: 96314
Reputation: 11
I think Hibernate provides desired functionality. Take a look at this, found on their official website: Mixing several NoSQL datastores in one application, e.g. use Neo4j for your friendship graph and MongoDB for your blog posts. Or mix NoSQL and relational databases.
Upvotes: 1
Reputation: 51
If you are using Java then you can use Hibernate OGM it provides Java Persistence support for NoSQL databases.
For more details visit http://hibernate.org/ogm/
Upvotes: 5
Reputation: 716
For the sake of completeness, PlayORM also supports MongoDB now. PlayORM is an object NoSQL mapping solution so you can write POJO’s and let it deal with all the details of marshalling/unmarshalling to MongoDB. Visit its documentation here
Upvotes: 1
Reputation: 41
There is nice work done earlier as:
refer to these links. it will be helpful to you.
Upvotes: 4
Reputation: 7392
What about Hibernate OGM? It provides JPA for No-SQL databases.
Upvotes: 34
Reputation: 821
Migration would be easier if you use Spring MongoTemplate (similar to HibernateTemplate).
Among its features is support for JPA annotations (although, I'm not sure to what extent).
See more: http://www.springsource.org/spring-data/mongodb
You'll need the following:
mongoTemplate.findById(id, MyClass.class);
mongoTemplate.insert(myObject);
Here's a concrete example with code: use-spring-and-hibernate-with-mongodb
Upvotes: 24
Reputation: 95
There is also kundera, which uses JPA-annotations to read/write your object from/to a mongodb. If you ara familiar with hibernate, it should be quite straightformard to use.
I recently tried Morphia, which takes the same approach, but with its own annotations. It works fine
Upvotes: 2
Reputation: 11
May this blog helps: http://drorbr.blogspot.com/2010/02/migrating-springhibernate-application.html Here Dror Bereznitsky describes nicely how to integrate a sping/hibernate based solution with mongodb.
Upvotes: 1
Reputation: 9140
Well just to give you an example, I am doing somehting simmilar. In ColdFusion, Hibernate is integrated and in order to save your Hibernate Object, you hvae to do EntitySave(Obj). However what we have done is build the Orm object, and then use a mongoDB Coldfusion component and just save the object by going mongo.Save(obj,collectionName).
Upvotes: 0
Reputation: 39887
You can't easily do this. The point of Hibernate is to map Java Objects to a relational database. Although Hibernate abstracts a lot of details away you still need to understand how relational databases work with things such as foreign and primary keys, and the performance implications of queries you run. MongoDB requires an entire different way of designing your database focusing on objects instead of columns and tables. while you may be able to create a Hibernate dialect for MongoDB creating a design that would work on both a relational database and a NoSql database will give you a design that works poorly on both.
Upvotes: 74