Skip to content


Subversion checkout URL

You can clone with
Download ZIP

Getting Started in 5 minutes

chhavigangwal edited this page · 60 revisions
Clone this wiki locally

We are going to give an example on persisting an object into Cassandra. But you are free to choose your own favourite data-store. (HBase, MongoDB and any relational database are other supported options in Kundera as of now.)

Set up Cassandra server

We're not going to delve into this as we assume you already have Cassandra server up and running on your machine. If not, there is a pretty good link to help you out. (This example assumes your cassandra server version is 1.x)

Download and include Kundera Jar

You can download Kundera dependency jar (only kundera-cassandra required for this example) from maven repository by including below code snippet into you pom.xml for your maven project and running

mvn eclipse:clean eclipse:eclipse


<project xmlns="" xmlns:xsi=""
            <name>Kundera Public Repository</name>
        <name>Kundera Public Missing Resources Repository</name>

Note :

  • Kundera from 2.12 release onwards has become JPA2.1 compliant whose one of the per-requisite is JDK1.7. Support over JPA 2.0 can be found in older branches (kundera-{project-version}-1.x)

  • With 2.9.1 release onwards artifact group id has been changed from




Write persistence.xml file

Make sure to put it under a META-INF folder in your classpath.

<persistence xmlns="" xmlns:xsi=""
    <persistence-unit name="cassandra_pu">
            <property name="kundera.nodes" value="localhost"/>
            <property name="kundera.port" value="9160"/>
            <property name="kundera.keyspace" value="KunderaExamples"/>
            <property name="kundera.dialect" value="cassandra"/>
            <property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
            <property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider"/>
            <property name="kundera.cache.config.resource" value="/ehcache-test.xml"/>                  

Write Entity class

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

@Table(name = "users", schema = "KunderaExamples@cassandra_pu")
public class User 
    private String userId;

    private String firstName;

    private String lastName;

    private String city;    

    public User()

    public String getUserId()
        return userId;
    public void setUserId(String userId)
        this.userId = userId;
    public String getFirstName()
        return firstName;
    public void setFirstName(String firstName)
        this.firstName = firstName;
    public String getLastName()
        return lastName;
    public void setLastName(String lastName)
        this.lastName = lastName;
    public String getCity()
        return city;
    public void setCity(String city)
    { = city;

Moment of Truth!

Create Keyspace and Column family in cassandra

amresh@impetus-ubuntu:/usr/local/apache-cassandra-1.2.5/bin$ ./cassandra-cli --host localhost --port 9160
Connected to: "Test Cluster" on localhost/9160
Welcome to the Cassandra CLI.
Type 'help;' or '?' for help.
Type 'quit;' or 'exit;' to quit.
[default@unknown]create keyspace KunderaExamples;
[default@unknown]use KunderaExamples;
[default@KunderaExamples]create column family users with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type;

Waiting for schema agreement...
... schemas agree across the cluster

Run below program.

If it throws any error, check our Troubleshooting section. If you are stuck somewhere, you can raise your issue on or here.

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class KunderaExample
    public static void main(String[] args)
        User user = new User();

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra_pu");
        EntityManager em = emf.createEntityManager();


Validate the persisted data from cassandra-cli

[default@unknown] use KunderaExamples;
Authenticated to keyspace: KunderaExamples
[default@KunderaExamples] list users;
Using default limit of 100
RowKey: 0001
=> (column=city, value=London, timestamp=1323551942371)
=> (column=first_name, value=John, timestamp=1323551942371)
=> (column=last_name, value=Smith, timestamp=1323551942371)

1 Row Returned.


Something went wrong with that request. Please try again.