我正在使用spring-data-cassandra并且需要使用jpa映射一个字段,在cassandra中是frozen<map<text, list<text>>>
类型
表脚本:
create table IF NOT EXISTS test (
id varchar,
name varchar,
target frozen<map<text, list<text>>>,
primary key (id, name)
);
我做了这样的事情:
@Column("target")
@CassandraType(type = DataType.Name.MAP, typeArguments = arrayOf( DataType.Name.MAP))
Map<String, List<String>> target;
但得到错误:
找不到请求操作的编解码器:[list < - > java.util.List];嵌套异常是 com.datastax.driver.core.exceptions.CodecNotFoundException: 找不到请求操作的编解码器:[list < - > java.util.List]
请删除@CassandraType
注释并添加驱动程序映射依赖项
用户模型
@Table(keyspace = "test_space", name = "user")
public class User {
@PartitionKey
private int id;
@Column
private String name;
@Column
private Map<String, List<String>> tags;
}
主要方法
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();
}
产量
User{id=2, name='user', tags={test=[test], tester=[one, two]}}
表数据
cqlsh:test_space> SELECT * FROM user ;
id | name | tags
----+------+----------------------------------------------
2 | user | {'test': ['test'], 'tester': ['one', 'two']}
(1 rows)
cqlsh:test_space>
依赖pom
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>3.0.0</version>
</dependency>