Mapping API

The Datastax Java driver provides a mapping API that helps to map our query results to Java classes. This API is provided as a separate artifact. We're using mapping API version 2.1.4 in our examples, below are dependency details:

// Maven Dependancy
<dependency>
   <groupId>com.datastax.cassandra</groupId>
   <artifactId>cassandra-driver-mapping</artifactId>
   <version>2.1.4</version>
</dependency>
// Gradle Dependancy
compile 'com.datastax.cassandra:Cassandra-driver-mapping:2.1.4'

The mapping API provides annotations to map a Java class to a Cassandra table. For example, our Status class can be mapped to Cassandra table status_updates_by_user, as in the following example of Status.java, updated as per the mapping API:

package cassandra.cassandraclient.model; ...

Get Apache Cassandra Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.