brew install Cassandra
cassandra -f
cqlsh
CREATE KEYSPACE Sample WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1};
use Sample;
CREATE TABLE Student(
id int,
name text,
dept text,
year_of_joining int,
PRIMARY KEY (id)
);
CREATE TABLE Staff (
id int,
name text,
dept text,
subjects list<text>,
PRIMARY KEY (id, dept)
);
INSERT INTO Student (id, name, dept, year_of_joining)
VALUES (1, 'Vicky', 'CSE', 2010);
INSERT INTO Staff (id, name, dept, subjects)
VALUES (1, 'Selvam', 'CSE', ['Compiler Design', 'Operating System']);
Ok, now the DB is ready..! Lets start building the Spring Boot part
Go to https://start.spring.io & choose dependecies web, cassandra. Note: Don't chose JPA dependency when you use Cassandra.
In application.properties, give the keyspace name.
spring.data.cassandra.keyspace-name=Sample
Create your own Repo interface extending CassandraRepository
interface StudentRepo extends CassandraRepository<Student, Integer> {
}