user3310115
user3310115

Reputation: 1460

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>

Upvotes: 1

Views: 626

Answers (2)

Alex Ott
Alex Ott

Reputation: 87154

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.

Upvotes: 1

Raheela Aslam
Raheela Aslam

Reputation: 482

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;

Upvotes: 0

Related Questions