找不到请求操作的编解码器:[list <varchar>&lt; - &gt; java.nio.HeapByteBuffer]

时间:2018-01-17 18:15:37

标签: ignite

当我尝试在Cassandra中插入列表数据类型列时,我遇到了从apache点燃存储数据到Cassandra表的问题

Cassandra表:

CREATE TABLE business_categories (
id int,
category_name TEXT,
sub_categories list<TEXT>,
PRIMARY KEY(category_name, id)
);

xml文件:

<persistence keyspace="ignite" table="business_categories">
    <keyspaceOptions>
        REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1}
        AND DURABLE_WRITES = true
    </keyspaceOptions>
    <tableOption>
        comment = 'Cache test'
        AND read_repair_chance = 0.2
    </tableOption>
    <keyPersistence class="com.cache.business.model.BusinessCategoriesKey" strategy="POJO"/>
    <valuePersistence class="com.cache.business.model.BusinessCategoriesValue" strategy="POJO"/>
</persistence>

密钥类对象:

public class BusinessCategoriesKey implements Serializable {

    private static final long serialVersionUID = 581472167344584014L;
    private int id;
    private String category_name;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getCategory_name() {
        return category_name;
    }

    public void setCategory_name(String category_name) {
        this.category_name = category_name;
    }

}

值类对象:

public class BusinessCategoriesValue implements Serializable {

    private static final long serialVersionUID = -1694694702874919854L;
    private List<String> sub_categories = new ArrayList<>();

    public List<String> getSub_categories() {
        return sub_categories;
    }

    public void setSub_categories(List<String> sub_categories) {
        this.sub_categories = sub_categories;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

}

我收到以下错误消息

  

引起:com.datastax.driver.core.exceptions.CodecNotFoundException:找不到请求操作的编解码器:[list&lt; - &gt; java.nio.HeapByteBuffer]

1 个答案:

答案 0 :(得分:0)

sub_categories字段是java.util.List,似乎Apache Ignite没有为这种Java类型提供适当的Cassandra类型的直接映射。 因此,只有在手动指定对象类型的所有映射详细信息并且字段类型本身正在实现java.io.Serializable接口时,才能将此字段持久保存到Cassandra中。 在这种情况下,该字段将作为blob持久保存到单独的表列中。

请尝试按以下方式修改您的代码:

CREATE TABLE business_categories (
    id int,
    category_name text
    sub_categories blob,
    PRIMARY KEY(category_name, id)
);

持久性描述符:

<persistence keyspace="ignite" table="business_categories">
<keyspaceOptions>
    REPLICATION = {'class' : 'SimpleStrategy', 'replication_factor' : 1}
    AND DURABLE_WRITES = true
</keyspaceOptions>
<tableOption>
    comment = 'Cache test'
    AND read_repair_chance = 0.2
</tableOption>

<keyPersistence class="com.cache.business.model.BusinessCategoriesKey" strategy="POJO"/>

<valuePersistence class="com.cache.business.model.BusinessCategoriesValue"
                  strategy="POJO"
                  serializer="org.apache.ignite.cache.store.cassandra.serializer.JavaSerializer">
    <field name="sub_categories" column="sub_categories"/>
</valuePersistence>

您可以在此处找到其他详细信息:Cassandra Integration Examples