Spring 数据 Cassandra,允许过滤

Spring data Cassandra, Allow filtering

我有以下table

CREATE TABLE magazines.magazine_name (
    frequency smallint,
    magazine_id varchar,
    magazine_name varchar,
    PRIMARY KEY (magazine_id,magazine_name)
);

我是否应该使用允许过滤器注释来执行以下存储库方法

@Query("SELECT * from magazine_name where magazine_id = ?0")
MagazineName findMagazineCQlQuery(String id);

因为我得到以下执行:

org.springframework.data.cassandra.CassandraInvalidQueryException:Query; 
CQL[com.datastax.oss.driver.internal.core.cql.DefaultSimpleStatement@c78c2039]; 
Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. 
If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING; 

nested exception is 
 com.datastax.oss.driver.api.core.servererrors.InvalidQueryException:
Cannot execute this query as it might involve data filtering 
and thus may have unpredictable performance. 
If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING

顺便说一下,我知道我可以使用查询方法甚至 findById 方法,但实际上我只是在试验 cql 查询并尝试了解它。

--更新 域对象

@Table(value = "magazine_name")
@Data
@Builder
public class MagazineName {

    @PrimaryKeyColumn(name = "magazine_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
    private String magazineId;
    @PrimaryKeyColumn(name = "magazine_name", ordinal = 1, type = PrimaryKeyType.CLUSTERED)
    private String name;
}

我定义的 table 和你的完全一样,这是我的存储库。我可以查询没有错误。

1.我的存储库

public interface IMagazineDao extends CrudRepository<Magazine, String> {

    @Query("SELECT * from magazine_name where magazine_id = ?0")
    Magazine findMagazineCQlQuery(String id);


}

2。申请

@SpringBootApplication
public class Application implements CommandLineRunner {
    
    @Autowired
    private IMagazineDao magazineDao;

    @Override
    public void run(String... args) throws Exception {
        this.magazineDao.save(new Magazine("magazine1", "name", (short) 1));
        this.magazineDao.findMagazineCQlQuery("magazine1");
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

3。杂志 class

@Table(value = "magazine_name")
public class Magazine {

    @PrimaryKeyColumn(name = "magazine_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
    private String magazineId;

    @PrimaryKeyColumn(name = "magazine_name", ordinal = 1, type = PrimaryKeyType.CLUSTERED)
    private String name;

    @Column
    private Short frequency;

    public Magazine() {

    }
    public Magazine(String magazineId, String name, Short frequency) {
        this.magazineId = magazineId;
        this.name = name;
        this.frequency = frequency;
    }

    public String getMagazineId() {
        return magazineId;
    }

    public void setMagazineId(String magazineId) {
        this.magazineId = magazineId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Short getFrequency() {
        return frequency;
    }

    public void setFrequency(Short frequency) {
        this.frequency = frequency;
    }
}