I faced lot of issues when trying to integrate Spring Data Cassandra with Cassandra 3.0. By default Spring supports Cassandra 2.x, however, when trying to use the same with Cassandra 3.x results in lot of issues.
You need to perform few changes in Spring classes to get it working with Cassandra 3.x
I have listed down below the changes required, hope this helps others who might be struggling with the same issue
POM.xml
You need to perform few changes in Spring classes to get it working with Cassandra 3.x
I have listed down below the changes required, hope this helps others who might be struggling with the same issue
POM.xml
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>1.3.4.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>cassandra-driver-core</artifactId>
<groupId>com.datastax.cassandra</groupId>
</exclusion>
<exclusion>
<artifactId>cassandra-driver-dse</artifactId>
<groupId>com.datastax.cassandra</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
Spring Changes
- package - org.springframework.data.cassandra.convert
- class - ColumnReader
- method - public Object get(int i)
return row.getMap(i, collectionTypes.get(0).asJavaClass(), collectionTypes.get(1).asJavaClass());
Replace it with
return row.getMap(i, cr.codecFor(collectionTypes.get(0)).getJavaType().getRawType(), cr.codecFor(collectionTypes.get(1)).getJavaType().getRawType());
Search for line
return row.getList(i, collectionTypes.get(0).asJavaClass());
Replace it with
return row.getList(i, cr.codecFor(collectionTypes.get(0)).getJavaType().getRawType());
Search for line
return row.getSet(i, collectionTypes.get(0).asJavaClass());
Replace it with
return row.getSet(i, cr.codecFor(collectionTypes.get(0)).getJavaType().getRawType());
- package - org.springframework.data.cassandra.mapping
- class - CassandraSimpleTypeHolder
- method - static block (no method)
Search for line
Class javaClass = dataType.asJavaClass();
Replace it with
Class javaClass = cr.codecFor(dataType).getJavaType().getRawType();
- package - org.springframework.data.cassandra.repository.query
- class - StringBasedCassandraQuery
- method - private String replacePlaceholders(String input, CassandraParameterAccessor accessor)
stringValue = "'" + CqlStringUtils.escapeSingle(value) + "'";
Replace it with
stringValue = "\"" + CqlStringUtils.escapeSingle(value) + "\"";
That's it, after these changes you should be able to use Spring with Cassandra 3.x
Do leave a reply if there are any issues / discrepancies.