Vivek Mishra's Blog

जॉय साथ है

साइकल एक है, पर बैठे हम चार हैं,

जॉय राइड है या नही पर जॉय साथ है.

धूप कड़क है या खिली खिली,

इससे कोई सरोकार नही, पर जॉय साथ है.


वो दूर कोई मंज़िल है, या क्षितिज,

बस पींगे मारते जा रहें हैं, सफ़र का मज़ा लिए जा रहे हैं.

जॉय राइड तो नही है शायद, पर जॉय साथ है!


आज एसी कार है, रफ़्तार है,

आँखों पे चस्मा है, बैठे बैठे गानो का आनंद लिए जा रहे है,

जॉय राइड तो है, पर… जॉय नही साथ है.



बचपन में पर्वत को देखकर मैं आवाज़ लगाता
था की मैं वहाँ ज़रूर पहुँचुगा. सब कहते थे की ये करेगा. आज उँचाई पर तो हूँ और आवाज़ भी लगाता हूँ, आवाज़ तो वापस सुनाई देती है पर वो लोग नही आते!

यह भर्म है या वो भ्रम था. ढूंड रहा हूँ



बंद कर दो ये दरवाजे या .. ये खिड़कियाँ खुली रहने दो.

शायद हवा रुक रुक के आए . झोंके तो ठीक  हैं ….पर ये बवंडर!….ये बवंडर बहा ले जाता है. देखो कुण्डी मजबूती से लगाना पता नही कब सब्र की तरह टूट जाए.

बंद दरवाज़े हमेशा किसी आहट को सुनना चाहते हैं ..पर… बंद ही रहने दो…  झोंके ही ठीक हैं​


Requesting Honorable Member of Parliament give up canteen food subsidy

A mutton curry for Rs 20, chicken curry for Rs 29, boiled rice Rs 4, so is boiled egg, masala dosa for Rs 6, vada for Rs 2, puri with veg for Rs 2, non-veg meal for Rs 33, and a three course lunch for Rs 61, veg/egg/chicken sandwiches at just Rs 3/4/6, burger for Rs 17, pizza for Rs 20, low fat cream with fruits for Rs 19, custard with fruits (low fat milk) for Rs 23, roomali rotti, chapatti or pappad at just Re 1. And from the Winter Session 2014, Hyderabadi biriyanis for Rs 50 and 20 among other things to the menu.

This 95-item menu is not from a Socialist-run Restaurant at the end of the Universe, but from the four canteens at the Parliament in Delhi, where many legislators are increasingly pushing for subsidy cuts in food, fuel and fertilisers among other things

I request to all honorable MP’s. Please GIVE IT UP.  

Please comment if you agree/disagree.

Perform CRUD over HBase using HBaseTestingUtility/EmbeddedHBase

EmbeddedHBase, Something similar to EmbeddedCassandraService. I have been looking for something like this since last year(March 2011) to incorporate the same in Kundera. HBaseTestingUtility really helped me to achieve continuous integration and also testing junits with in-memory HBase server. So here i am sharing some code snippets about how to configure and start EmbeddedHBase:

  • HBaseCli: Responsible for initializing and configuring HBaseTestingUtility.

public final class HBaseCli

/** The Constant logger. */
private static final Logger logger = LoggerFactory.getLogger(HBaseCli.class);

/** The utility. */
private static HBaseTestingUtility utility;

private static Boolean isStarted = false;


  • Start cluster: (You can change settings for zookeeper port, timeout etc.)

* Starts a new cluster.
public static void startCluster()
if (!isStarted)
File workingDirectory = new File(“./”);
Configuration conf = new Configuration();
System.setProperty(“”, workingDirectory.getAbsolutePath());
conf.set(“”, new File(workingDirectory, “zookeeper”).getAbsolutePath());
conf.set(“”, “file:///”);
conf.set(“zookeeper.session.timeout”, “180000”);
conf.set(“hbase.zookeeper.peerport”, “2888”);
conf.set(“”, “2181”);
conf.set(HConstants.HBASE_DIR, new File(workingDirectory, “hbase”).toURI().toURL().toString());
catch (MalformedURLException e1)

Configuration hbaseConf = HBaseConfiguration.create(conf);
utility = new HBaseTestingUtility(hbaseConf);
MiniZooKeeperCluster zkCluster = new MiniZooKeeperCluster(conf);
catch (Exception e)
throw new RuntimeException(e);
isStarted = true;

This should get Zookeeper, Hadoop(datanode, namenode, tasktracker etc.) and HBase master server started.

Create table

public static void createTable(String tableName)
if (!utility.getHBaseAdmin().tableExists(tableName))
utility.createTable(tableName.getBytes(), tableName.getBytes());
{“Table:” + tableName + ” already exist:”);
catch (IOException e)

Add Column

public static void addColumn(String tableName, String columnFamily)
utility.getHBaseAdmin().addColumn(tableName, new HColumnDescriptor(columnFamily));
catch (InvalidFamilyOperationException ife)
{“Column family:” + columnFamily + ” already exist!”);
catch (IOException e)

Stop Cluster:

public static void stopCluster()
if (utility != null)
utility = null;
catch (IOException e)

Happy Programming :)

How to: CRUD and JPA association handling using Kundera

Recently we have released Kundera-2.0.5. This post is all about demonstrating how to perform CRUD and association handling using kundera. Kundera is now enabled to use secondary index support provided by cassandra(0.7.x onwards), Hence this example will demonstrate how to leverage that benefit using same JPA style within in Kundera
Example i am referring can be found Here.
Run this script to create column family in cassandra with indexes: =>
  • create keyspace KunderaExamples;
  • create column family PERSON with comparator=UTF8Type and column_metadata=[{column_name: PERSON_NAME, validation_class:UTF8Type, index_type: KEYS}, {column_name: AGE, validation_class:IntegerType, index_type: KEYS}];


package com.impetus.kundera.examples.crud;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;/**
* The Class Person.
@Table(name = "PERSON", schema = "KunderaExamples@twissandra")
public class PersonCassandra
{/** The person id. */
@Column(name = "PERSON_ID")
private String personId;/** The person name. */
@Column(name = "PERSON_NAME")
private String personName;/** The age. */
@Column(name = "AGE")
private Integer age;// Followed by getters and setters method

Configuration : Persistence.xml

<persistence xmlns=”;

<!– Persistence Units for twissandra application –>
<persistence-unit name=”twissandra”>
<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” value=”Pelops”/>
<property name=”kundera.cache.provider.class” value=”com.impetus.kundera.cache.ehcache.EhCacheProvider”/>
<property name=”kundera.cache.config.resource” value=”/ehcache-test.xml”/>

Now, if you notice @ table annotation:

@Table(name = “PERSON”, schema = “KunderaExamples@twissandra”)

For cassandra, “PERSON” is specified column family and schema denotes “keyspace@puname”.

Entity definition:
public class PersonTest
/** The emf. */
private EntityManagerFactory emf;
/** The em. */
private EntityManager em;

.... methods defining various operations.


Initialize entity manager
emf = Persistence.createEntityManagerFactory("twissandra");
em = emf.createEntityManager();
Insert :
public void onInsertCassandra()
{Object p1 = prepareData("1", 10);
Object p2 = prepareData("2", 20);
Object p3 = prepareData("3", 15);

private PersonCassandra prepareData(String rowKey, int age)
PersonCassandra o = new PersonCassandra();
return o;

Find By Id:
public void onFindByIdCassandra()
PersonCassandra p = findById(PersonCassandra.class, "1", em);
private E findById(Classclazz, Object rowKey, EntityManager em)
return em.find(clazz, rowKey);
Find By Name:
public void onFindByName()
findByName(em, "PersonCassandra", PersonCassandra.class, "vivek", "PERSON_NAME");
* Assert find by name.
* @param the element type
* @param em the em
* @param clazz the clazz
* @param e the e
* @param name the name
* @param fieldName the field name
private void findByName(EntityManager em, String clazz, E e, String name, String fieldName)

String query = "Select p from " + clazz + " p where p."+fieldName+" = "+name;
// // find by name.
Query q = em.createQuery(query);
List results = q.getResultList();

Find By Name and Age:

public void onFindByNameAndAge()
findByNameAndAge(em, "PersonCassandra", PersonCassandra.class, "vivek", "10", "PERSON_NAME");
private void findByNameAndAge(EntityManager em, String clazz, E e, String name, String minVal, String fieldName)

Query q = em.createQuery("Select p from " + clazz + " p where p."+fieldName+" = "+name+" and p.AGE > "+ minVal);
List results = q.getResultList();


Find By Range:
public void onFindByRange()
findByRange(em, "PersonCassandra", PersonCassandra.class, "10", "20", "PERSON_ID");
private void findByRange(EntityManager em, String clazz, E e, String minVal, String maxVal, String fieldName)

// find by Range.
Query q = em.createQuery("Select p from " + clazz + " p where p."+fieldName+" Between "+minVal+" and "+maxVal);
List results = q.getResultList();

Find by Name and “<” and “>”

public void onFindByNameAndAgeGTAndLT()
findByNameAndAgeGTAndLT(em, "PersonCassandra", PersonCassandra.class, "vivek", "10", "20", "PERSON_NAME");
private void findByNameAndAgeGTAndLT(EntityManager em, String clazz, E e, String name, String minVal, String maxVal, String fieldName)
// // // find by name, age clause
Query q = em.createQuery("Select p from " + clazz
+ " p where p."+fieldName+" = " + name + " and p.AGE > "+ minVal+ " and p.AGE < " +maxVal);
List results = q.getResultList();


Self Association:

Example demonstrating about how to define and perform bi directional self association is available Here

Using Default lucene index

Still there are some operations not supported by enabling cassandra secondary indexes(e.g. indexing and search over super column values etc.). Also indexing support over HBase is not yet mature, so Kundera does provide default lucene indexing support for all sort of find operation. What you need to do is simply provide given below property:

<property name=”index_home_dir” value=”$LUCENE_DIR_PATH”/>

This will simply start storing and indexing records on specified local/remote location.

Can we use same example for other supported data stores(e.g. Mongo, HBase, Mysql etc) ?

Answer is YES.  changes required:

  • Define persistence unit in persistence.xml
  • Create script specific to intended database.
  • Modify entity definition (e.g. PersonCassandra) for correct column family name or table name.(see @table annotation above)
  • Modify entity manager factory instantiation for correct column family name.

That’s it !

  • Example to refer for different data type support can be found Here
  • Example to refer for cross data store operations can be found Here
  • Example to refer for flickr like application can be found here

Setup Kundera with standalone Cassandra


Setup Kundera with standalone Cassandra:

Note: Currently Kundera supports Cassandra 0.8.2. You can download Cassandra releases from here.

1)      Setup an environment variable “CASSANDRA_HOME” to Cassandra home directory (e.g. D:\vivek\source\cassandra-0.8.2)

2)      Download Kundera configurator from here

3)      Change to the directory where this jar file is saved and run the below command:
java -jar kunderaConfigurator.jar

You’ll see an output similar to the one shown below:

4)       In case you want to use Kundera executable to develop your application, you can download it from here. (Else you can build Kundera-2.0.3 source code for the same).

5)       You need to add “”, as unfortunately Cassandra release is not able to locate this file internally within executable jar. (You can find this file /src/main/resources)So you need to put this as follows:



OR like:

6)     Modify your persistence.xml to include

<property name=“server.config” value=“$CASSANDRA_HOME/conf/cassandra.yaml”/>

 Replace $CASSANDRA_HOME -> your cassandra root directory folder.


And that’s it. Enjoy working with Kundera


Get every new post delivered to your Inbox.

%d bloggers like this: