Aditya
Aditya

Reputation: 115

Cassandra through java\hibernate

I started learning Cassandra using java, after completing hibernate. I am really surprised by the way in which data is inserted/pulled/deleted from cassandra through java while java is moving backwards these days. Because, hibernate gives a very easy way to communicate with the database, a java developer has no need to know the database query syntax,etc. It is mostly method based operations which are used to communicate with the database. But if i want to communicate with cassandra through java, everything is in an SQL format i mean they named it as CQL but i am really surprised by the way in which things are happening when i compare it to the hibernate.

My question here is, is there any way to communicate/do CRUD operations on cassandra through java in O-R mapping style or can hibernate supports cassandra connectivity?

Upvotes: 4

Views: 9195

Answers (3)

Mateen
Mateen

Reputation: 1671

Yes Hibernate is supporting cassandra but it is still under experimental stage!!

so read the below notes carefully before you use it.

This implementation uses CQL3 over the native wire protocol with java-driver. The currently supported version is Cassandra 2.1.

To add the dependencies via Maven, add the following module:

<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-cassandra</artifactId>
<version>5.0.4.Final</version>

To get started you will need to configure the following properties:

hibernate.ogm.datastore.provider

hibernate.ogm.datastore.host

hibernate.ogm.datastore.database

source

Upvotes: 0

Dip
Dip

Reputation: 344

You can perform crud operation with Cassandra using Solr or Spark. Example
Now, do not compare Cassandra with any RDBMS. There is no concept of Relational in Cassandra. So, be careful. If you want to fetch data from Cassandra without much knowledge of Cassandra (similar to Hibernate), you may try Spark:

JavaRDD<Student> studentObj = CassandraJavaUtil.javaFunctions(sc).cassandraTable("schema", "student_table",CassandraJavaUtil.mapRowTo(Student.class)).where("id=1");

Remember, Spark is mainly for Analytics purpose. I also found some new OGM tools that you may try:

  1. http://hibernate.org/ogm/

  2. https://github.com/impetus-opensource/Kundera

Upvotes: 2

Chris Lohfink
Chris Lohfink

Reputation: 16400

Cassandra is not a relational database, using a relational mapper isn't going to be as straight forward. There are no joins and it does not support SQL.

The java drivers object mapper is probably closest to what your looking for though. For basic CRUD mappings on Cassandra tables. See documentation here: https://docs.datastax.com/en/developer/java-driver/3.0/supplemental/manual/object_mapper

ie

@Table(name = "posts")
public static class Post {

    private String title;
    private String content;
    private InetAddress device;

    @ClusteringColumn
    @Column(name = "post_id")
    private UUID postId;

    @PartitionKey
    @Column(name = "user_id")
    private UUID userId;


    private Set<String> tags;
    ...
}

Upvotes: 5

Related Questions