Cassandra Springboot Frozen column exception

I have a springboot application which I hooked up with cassandra. I am trying to create a map inside a map but getting the below exception.

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

Code

@Table
@Data
public class AssessmentSubmissionEntity {

    @PrimaryKey()
    private UUID id;

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


}

man

<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 answers

  • answered 2018-11-08 06:58 Raheela Aslam

    Please have a look into Non frozen collections and user defined types on Cassandra 2.1.8.

    You need to add frozen keyword:

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

  • answered 2018-11-08 08:04 Alex Ott

    When you're have frozen collections in the database, you also need to mark whole column as @Frozen, or for maps you can mark the key or value as frozen with @FrozenKey and @FrozenValue if you want to freeze only particular part of the map. Here is example to froze the whole column.

    @Table
    @Data
    public class AssessmentSubmissionEntity {
    
        @PrimaryKey()
        private UUID id;
    
        @Frozen
        @Column
        private Map<String, Map<String,Integer>> assessmentMap;    
    }
    

    If you want to freeze only the data inside Map, then you need to write it as:

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

    More information & examples is in the documentation.