本文介绍了无法识别 Springboot cassandra 冻结值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与 cassandra 相关联的 springboot 应用程序.我正在尝试在地图内创建地图,但出现以下异常.在我看来,即使我使用 @FrozenValue,它仍然发送没有关键字 frozen

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. Seems to me that even though I use @FrozenValue, it is still sending the cal without the keyword frozen

错误

Caused by: org.springframework.data.cassandra.CassandraInvalidQueryException: Query; CQL [CREATE TABLE IF NOT EXISTS assessmentsubmissionentity (studentid text, assessmentid text, values map<text, map<text, text>>, PRIMARY KEY ((studentid, assessmentid)));]; Non-frozen collections are not allowed inside collections: map<text, map<text, text>>; nested exception is com.datastax.driver.core.exceptions.InvalidQueryException: Non-frozen collections are not allowed inside collections: map<text, map<text, text>>
    at org.springframework.data.cassandra.core.cql.CassandraExceptionTranslator.translate(CassandraExceptionTranslator.java:139) ~[spring-data-cassandra-2.1.2.RELEASE.jar:2.1.2.RELEASE]
    at org.springframework.data.cassandra.core.cql.CassandraAccessor.translate(CassandraAccessor.java:334) ~[spring-data-cassandra-2.1.2.RELEASE.jar:2.1.2.RELEASE]
Caused by: com.datastax.driver.core.exceptions.InvalidQueryException: Non-frozen collections are not allowed inside collections: map<text, map<text, text>>
    at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:49) ~[cassandra-driver-core-3.6.0.jar:na]

代码

@Table
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class AssessmentSubmissionEntity implements Serializable {

    @PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED)
    private String studentId;

    @PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED)
    private String assessmentId;

    @FrozenValue
    @Column
    private Map <String, Map<String, String>> values;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        AssessmentSubmissionEntity that = (AssessmentSubmissionEntity) o;
        return Objects.equals(studentId, that.studentId) &&
                Objects.equals(assessmentId, that.assessmentId) &&
                Objects.equals(values, that.values);
    }

    @Override
    public int hashCode() {

        return Objects.hash(studentId, assessmentId, values);
    }
}

马文

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-cassandra</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.datastax.cassandra</groupId>
                    <artifactId>cassandra-driver-core</artifactId>
                </exclusion>
            </exclusions>
        </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>

推荐答案

Spring Data for Cassandra 存在一个问题——他们没有针对冻结集合的映射.请参阅他们的 JIRA 中的 DATACASS-465 - 它是一年多以前提交的,但有是不是没有进展...

It's a problem with Spring Data for Cassandra - they don't have mapping for frozen collections. See DATACASS-465 in their JIRA - it was filed more than year ago, but there is no progress on it...

我认为唯一的解决方案是使用 DataStax 的 Java 驱动程序中的对象映射器,或者通过 CQL 管理您的表.

I think that only solution is to use Object Mapper from the DataStax's Java driver, or manage your tables via CQL.

这篇关于无法识别 Springboot cassandra 冻结值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 10:59