Skip to content

Object to NoSQl Data mapping

karthikprasad13 edited this page Mar 25, 2015 · 32 revisions

Data Storage in different datastores :

Different NoSQL datastores have different ways of storing data which may be in form of key-value pairs, columnfamilies, document objects or graphs. The main purpose of storing data in any of these datastores is to achieve simplicity in design, better performance and scalability. But in order to manipulate data stored in "NoSQL" fashion and leverage its benefits there has to be a solution which allows you to interact with that data in familiar way as was done with traditional databases. Kundera enables you to play with data stored in NoSQL databases in same old way by using specifications of JPA and thus enabling you to use the features of these datastores with minimal learning.

Defining Objects in Kundera :

Kundera is a ORM tool for NoSQL databases. It is a JPA compliant object mapping solution for several NoSQL databases. Objects in Kundera are maintained in form of Entities and are recognized via JPA annotations.

Kundera => Cassandra Data Model

Kundera maps data in Cassandra or any other datastore seamlessly.

  • Cassandra Keyspace can be specified in persistence.xml as
<property name="kundera.keyspace" value="KunderaExamples"/>
  • As per JPA specifications, Entity maps to a table and its attributes to columns.

e.g.

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
public class User 
{
    @Id
    private String userId;
    
    @Column(name="first_name")
    private String firstName;
    
    @Column(name="last_name")
    private String lastName;
    
   
}

Equivalent in Cassandra :

CREATE TABLE "User" (
  key text PRIMARY KEY,
  first_name text,
  last_name text
) ;

Kundera facilitates using key features of Cassandra with utmost ease. A brief explanation for the same can be found at the respective links below:

JPA Association modelling

As a JPA solution, Kundera maps each associated entity in JPA way, (e.g., each associated entity in separate table). However keeping recent development around Cassandra,MongoDB etc in mind,Kundera team is analyzing and working on alternative path on dealing with association handling.

Under the hood

When you call persist on an object :

em.persist(object);

You may refer architecture of Kundera for further details.

Clone this wiki locally