середу, 6 лютого 2013 р.

Working with MongoDB using Kundera

When we are talking about JPA2 we usualy imaging relation database and one of ORM (Hibernate or EclipseLink). However, JPA is general approach not only for relation system. It covers NoSQL as well. And one of wonderful JPA implementation oriented on non-relation databases is Kundera.

Initially Kundera was developed for Cassandra. It seems to be a good idea, if you don't use relation you don't have the main problem of different ORM frameworks:) HBase was the next database supported by Kundera, and now is the time for MongoDB



Also, support for relation schema was anonced! Awesome! Be honest, I don't believe the it'll work well. Otherwise we'll get power competitor to Hibernate and K.
But, Kundera is awesome one to creating prototype, when you need base CRUD operations and just to want to try you application with Cassandra, HBase or MongoDB. The beautiful parts is possibility to write JPQL queries instead of native database structures.

Let's figure out how we can use Kundera with MongoDb... Mongo JPA




Just simple introduction in MongoDB (skipt this part if you are familar with Mongo). Mongo DB is schemaless document-oriented database which save all entities as BSON documents (think about that as binary JSON). Documents are grouped in collection. As it's schema-less db you can put any object (document) in one collection. But in the real applciation you will group one-type objects into colelction. As I said, documents are JSON objects, so you can use embedded documents to group objects (for example, blog post and all comments you can put into one document). You can query you collection, but no SQL. Special construction is appears here - it is very unusual for SQL developer, but it has the same power (and more - you can use powerful MapReduce to perform simple analytic on Mongo collections)

Back to JPA. You'll be surprised, but it'is still JPA and you won't found difference in compare to writing code for Mysql, for example.
If you are familiar with SQL or JPA-QL and you need to start with MongoDB, this framework is a beautiful chance to start. You won't need to write Mongo-specific construction, you can use JPA-QL. 

So, if you need simple CRUD just to check your MVP,. you should try this nice framework!

Further reading 1 and 2

Немає коментарів:

Дописати коментар