1

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>
user3310115
  • 1,372
  • 2
  • 18
  • 48

2 Answers2

1

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.

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
  • I'm still getting this exception. Some how JPA doesn't seem to be recognising the frozen value. It still send cal query without frozen. Any idea why this might be happening? – user3310115 Nov 14 '18 at 06:26
  • You mentioned only Spring Boot so I did think that you use Object Mapper from DataStax driver & gave you a link to its documentation. If you're using Spring Data for Cassandra, then you can't make it work until the https://jira.spring.io/browse/DATACASS-465 is implemented... – Alex Ott Nov 14 '18 at 08:13
0

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;
Raheela Aslam
  • 452
  • 2
  • 13