1
votes

I'm using spring-data-cassandra and need to map a field using jpa that in cassandra is of type frozen<map<text, list<text>>>

table script:

create table IF NOT EXISTS test (
id varchar,
name varchar,
target frozen<map<text, list<text>>>,
primary key (id, name)

);

I made something like this:

@Column("target")
@CassandraType(type = DataType.Name.MAP, typeArguments = arrayOf( DataType.Name.MAP))   
Map<String, List<String>> target;

but get the error:

Codec not found for requested operation: [list <-> java.util.List]; nested exception is
com.datastax.driver.core.exceptions.CodecNotFoundException:
Codec not found for requested operation: [list <-> java.util.List]

1
Please improve your question to make clear what you're actually asking?mp911de

1 Answers

1
votes

Please remove @CassandraType annotation and add driver mapping dependency

User model

@Table(keyspace = "test_space", name = "user")
public class User {

    @PartitionKey
    private int id;

    @Column
    private String name;

    @Column
    private Map<String, List<String>> tags;

}

main method

public void run(String... args) throws Exception {
    Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").build();
    Session session = cluster.connect("test_space");
    MappingManager manager = new MappingManager(session);
    Mapper<User> userMapper = manager.mapper(User.class);
    System.out.println(userMapper.get(2));
    session.close();
    cluster.close();
}

output

User{id=2, name='user', tags={test=[test], tester=[one, two]}}

table data

cqlsh:test_space> SELECT * FROM user ;

 id | name | tags
----+------+----------------------------------------------
  2 | user | {'test': ['test'], 'tester': ['one', 'two']}

(1 rows)
cqlsh:test_space> 

dependency pom

    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-mapping</artifactId>
        <version>3.0.0</version>
    </dependency>