I am using Java language.I have to use ORM framework with MongoDb as Database.I have two options Morphia or Spring Data Mongo support.As far i am able to get details , it has been found Spring Data Mongo is better to use since: 1)It provides better DAO out of box inbuilt classes. 2)It has larger community base.
Are there any performance based differences between the two.And if there which one is better in which condition.Also i have requirement of multitenancy .After little search i found that there is very simple custom implementation in Spring Data Mongo to do the same.But in Morphia it is somewhat difficult.Does achieving multitenancy in Morphia diificult(where we need to write a lot of boiler plate code)
Morphia is a wrapper around the Java driver for MongoDB. It acts as an ODM (Object Document Model) for MongoDB documents. Its original goal was to provide an easy mapping to POJO (Plain Old Java Objects). Nowadays, newer versions of the Java driver support this mapping out of the box.
So I'd say that MongoTemplate is a better option, unless you have a very elaborated POJO model or need the custom queries capabilities of MongoRepository for some reason. Good points/examples. However your race condition example and undesired result can be avoided using @Version to prevent that very scenario.
Spring Data for MongoDB is part of the umbrella Spring Data project which aims to provide a familiar and consistent Spring-based programming model for new datastores while retaining store-specific features and capabilities.
MongoTemplate provides a simple way for you to save, update, and delete your domain objects and map those objects to documents stored in MongoDB. You can save, update and delete the object as shown below. MongoOperations is the interface that MongoTemplate implements.
I have been using Spring-data and I guess I feel somehow it lags as far as maturity is concerned.
It's good for all the practical purposes but the features mongo provides in it's full glory, Spring-data is slow to map that as a driver specially when it comes to aggregation.
As far as performance goes, Spring-data doesn't lag imo.
Sometime I get weird behaviors. Some of their annotation silently doesn't work at some places and for my life I cannot figure out why?
But as an overall implementation it's quite helpful in the way that it provides a robust structure on which your application can grow. It also is easy if you are coming from SQL background since you can draw a parallel between jdbcTemplate and mongoTemplate (though one needs to be cautious)
I seriously considered using Morphia, but dropped the idea since spring-data was providing a more structured ways. Looks like in Morphia we would have to implement some structure on our own which has pros and cons but You usually want to avoid doing it. Since there is a risk of boiler-plate codes, there is a learning curve for 'your' structure for new members.
On the pros side, I am sure Morphia provides more extensiblity leading you to enjoy the ability to suck most out of mongo features. It also is lightweight compared to Spring data.
Morphia is the way to go. Pretty stable, very good Play integration and offers access to all Mongo driver features if you need more torque. Reference resolution, entity embedding are working as expected. You get lifecycle annotations too, which are pretty useful for boilerplate persistence code.
I personally like spring-data because of the hades project... You don't need to implement the DAOs. You just write the interface and spring data automatically provides it to you. However Spring Data Mongodb implementation seems a little buggy in my initial trial. If you have hard dates and is working on a production quality product, probably it is wise to choose Morphia.
To get more information and implementation examples : mongodb-java-comparison/
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