Search code examples
javaspringspring-bootcassandradatastax

Spring Cassandra model mapping


I have a table as following

col1 text,
col2 timestamp,
col3 text,
col4 text,
col5 text,
col6 date,
col7 time,

I do not know how to create a bean class for the above table. So far i have created a bean with following keys. But it does not work

@PrimaryKey
String col1;

Date col2;

String col3;

String col4;

String col5;

Date col6;

String col6;

Please help me to handle Cassandra datatype such as timestamp, time and date in Spring.


Solution

  • ┌───────────┬────────────────────────────────────────┐
    │ timestamp │ java.util.Date                         │
    ├───────────┼────────────────────────────────────────┤
    │ date      │ com.datastax.driver.core.LocalDate     │
    ├───────────┼────────────────────────────────────────┤
    │ time      │ long                                   │
    └───────────┴────────────────────────────────────────┘
    

    1. Spring Data for Apache Cassandra - 13.1. Data Mapping and Type Conversion
    2. Java Driver for Apache Cassandra - CQL to Java type mapping