Cassandra Springboot冻结列异常

时间:2018-11-08 06:25:34

标签: spring-boot cassandra

我有一个与cassandra连接的springboot应用程序。我正在尝试在地图内创建地图,但出现以下异常。

com.datastax.driver.core.exceptions.InvalidQueryException: Non-frozen collections are not allowed inside collections: map<text, map<text, int>>

代码

@Table
@Data
public class AssessmentSubmissionEntity {

    @PrimaryKey()
    private UUID id;

    @Column
    private Map<String, Map<String,Integer>> assessmentMap;


}

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-cassandra</artifactId>
        </dependency>
        <dependency>
            <groupId>com.datastax.cassandra</groupId>
            <artifactId>cassandra-driver-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.datastax.cassandra</groupId>
            <artifactId>cassandra-driver-mapping</artifactId>
        </dependency>

2 个答案:

答案 0 :(得分:1)

当数据库中有冻结集合时,还需要将整列标记为@Frozen,对于地图,您可以将键或值标记为@FrozenKey和{{1 }}如果只想冻结地图的特定部分。这是冻结整个列的示例。

@FrozenValue

如果只想冻结Map中的数据,则需要将其写为:

@Table
@Data
public class AssessmentSubmissionEntity {

    @PrimaryKey()
    private UUID id;

    @Frozen
    @Column
    private Map<String, Map<String,Integer>> assessmentMap;    
}

更多信息和示例在documentation中。

答案 1 :(得分:0)

请查看Non frozen collections and user defined types on Cassandra 2.1.8

您需要添加冻结的关键字:

@Column
private Map<String, frozen Map<String,Integer>> assessmentMap;