Hector-Kundera

by Vivek Mishra


Feature Kundera GORA Hector
ORM Yes Yes Yes
JPA Compliant Yes No
Annotation Based Yes No Yes
Index Support Yes Yes NO
Second Level Cache Yes(Optional) No No
NoSql Abstraction Yes Yes
Entity relationship

Support

Yes No No
Native query support Yes No No

 

JPA Compliant& Annotation Based:

Kundera

Entity Definition:

@Entity

// makes it an entity class

@ColumnFamily(family="Authors", keyspace="Blog")

// assign ColumnFamily type and name

Public class Author implements Serializable{

/** Theusername. */

@Id

// row identifier

String username;

/** The email address. */

@Column(name = "email")

// override column-name

String emailAddress;

/** The country. */

@Column

String country;

/** The registered. */

@Column(name = "registeredSince")

@Temporal(TemporalType.DATE)

@Basic

Date registered;

/** The name. */

String name;

/**

* Instantiates a new author.

*/

public Author() { // must have a default constructor

}

}

@ColumnFamily: Defines column family and keyspace of given entity.

Entity Manager:

Configuration conf = new Configuration();

Conf.getEntityManager(“unit-name”);


 

Persistence and Search Using EntityManager :

/**

     * Test save authors.

     *

     * @throws Exception the exception

     */

Public void testSaveAuthors() throws Exception {

        String key = System.currentTimeMillis() + "-author";

        Author aObj = createAuthor(key, "a@a.org", "India", new Date());

        manager.persist(aObj);

// check if saved?

        Author aObj_db = manager.find(Author.class, key);

        assertEquals(aObj, aObj_db);

    }

/**

     * Creates the author.

     *

     * @param username the user name

     * @param email the email

     * @param country the country

     * @paramregisteredSince the registered since

     *

     * @return the author

     */

Private static Author createAuthor(String username, String email, String country, Date registeredSince) {

        Author author = newAuthor();

        author.setUsername(username);

        author.setCountry(country);

        author.setEmailAddress(email);

        author.setRegistered(registeredSince);

       return author;

    }

 

HECTOR:

Entity Definition:

Package com.mycompany.furniture;

Import javax.persistence.Column;

Import javax.persistence.DiscriminatorValue;

Import javax.persistence.Entity;

@Entity

Public class Chair {

@Column(name="recliner")

Private Boolean recliner;

@Column(name="arms")

Private boolean arms;

Public Boolean isRecliner() {

  return recliner;

  }

Public void setRecliner(boolean recliner) {

  this.recliner = recliner;

 }

Public boolean isArms() {

  return arms;

  }

Public void setArms(boolean arms) {

  this.arms = arms;

 }

}

 

Entity Manager:

<code

EntityManagerFactory entityManagerFactory;

entityManagerFactory = Persistence.createEntityManagerFactory(“unit-name”); 

EntityManagerem = entityManagerFactory.createEntityManager();


 

 

Persistence and Search Using EntityManager :

    Chair stb = new Chair();

    stb.setId(1);

    stb.setRecliner(true);

    em.persist(stb);

 

However,HECTOR and KUNDERA both are JPA complined. Additionally Kundera provides a way to search for entities by executing native query(i.e. search by any key)

 

Native Query(Search by any value):

Query q = entityManager.createQuery(“select a from Author a where         

          a.countrylike :country”);

          q.setParameter(“country”, country);

          List<Author> authors = q.getResultList();

 

Secondry Index support:Secondry index support is built with in Kundera for Cassandra and as well as for HBase using Lucene.

NoSql abstraction:

With respect to a developer, Kundera and Hector are drop dead simple to use and hides complexity of underlying APIs.

Additional Supports:

1)  Additionally Kundera provides support for relationship between entities.

2)  Second level cache support is provided by Kundera. (Which might be useful for other NoSqls).

Hector looks to me more than Object Mapper. But Kundera is designed and developed keeping ORM and JPA in mind.