2
votes

I have problem storing field of List as field of my table in cassandra database.

I'm using spring-data-cassandra, version 1.4.1.RELEASE.

My model contains:

@Column
@CassandraType(type = DataType.Name.LIST)
private List<Integer> somedata;

I would like to auto create my db tables with SchemaAction.RECREATE_DROP_UNUSED Schema action in my config class:

@Override
public SchemaAction getSchemaAction() {
    return SchemaAction.RECREATE_DROP_UNUSED;
}

It tries to create table, but following exception occurs:

Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: expected 1 of typed arguments for the property  'somedata' type is 'interface java.util.List' in the entity <my class here>
2

2 Answers

9
votes

Ok, found solution after digging into spring-data-cassandra source:

@CassandraType(type = DataType.Name.LIST, typeArguments = { DataType.Name.FLOAT } )
private List<Float> position;

You need to add typeArguments, to specify DataType of generic type. Exception mentioned in question is thrown when invalid number of those typeArguments is passed. In my case there was 0 and 1 is required.

@Column annotation proved to be not required here.

0
votes

There is no need to provide CassandraType annotation over the field as long as you are using primitive or Wrapper type objects. Following works fine for me.

@PrimaryKey
int id;
String name;
int num;
List<Integer> marks;

I am using spring-data-cassandra with version 1.4.2.RELEASE. Please update if you still face the issue.