Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Cassandra存储库-如何使用空集群键进行搜索_Java_Database_Spring_Cassandra_Repository - Fatal编程技术网

Java Spring Cassandra存储库-如何使用空集群键进行搜索

Java Spring Cassandra存储库-如何使用空集群键进行搜索,java,database,spring,cassandra,repository,Java,Database,Spring,Cassandra,Repository,我有一个关于使用SpringCassandra存储库搜索查询的问题。我有一个表,其中一个分区键和一个集群键一起作为复合主键。因此,在映射层中,我使用@PrimaryKeyClass和@PrimaryKeyColumn为PrimanyKey创建一个类,然后使用@PrimaryKey作为映射类 该表是使用以下cql创建的 CREATE TABLE user_mobile (phonenum text,memberid uuid,gender text,nickname text,photo time

我有一个关于使用SpringCassandra存储库搜索查询的问题。我有一个表,其中一个分区键和一个集群键一起作为复合主键。因此,在映射层中,我使用@PrimaryKeyClass和@PrimaryKeyColumn为PrimanyKey创建一个类,然后使用@PrimaryKey作为映射类

该表是使用以下cql创建的

CREATE TABLE user_mobile (phonenum text,memberid uuid,gender text,nickname text,photo timeuuid,PRIMARY KEY (phonenum, memberid))
我创建了一个名为PK_UserMobile的类作为主键类

@PrimaryKeyClass
  public class PK_UserMobile implements Serializable {
  @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED)
  private String phoneNum;
  @PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.CLUSTERED)
  private UUID memberId;
......
}
我的映射类是这样的

@Table("user_mobile")
public class UserMobile extends BaseDto {

 @PrimaryKey
 private PK_UserMobile pk;

........
}
可以像“从用户_mobile中选择*,其中phonenum='xxxxxxxxx';”这样运行cql。所以我想只使用分区键搜索这个表是可以的。当我尝试使用SpringCassandra存储库进行搜索时,似乎需要我提供phonenum和memberid的值来搜索用法。如果我只设置phonenum的值,则会引发以下异常

"com.datastax.driver.core.exceptions.InvalidQueryException: Invalid null value in condition for column memberid. "

所以我想知道我是否应该传入任何特殊的空对象作为搜索条件?或者我应该用其他方式做吗?谢谢。

这可能是因为您使用了标准CRUD存储库函数
findById
。要解决此问题,请使用以下模式在存储库中声明查询方法:

通过{key class name}{key class的属性}查找

在您的情况下,您的查询方法是:

List<UserMobile> findByPK_UserMobilePhoneNum(String phoneNum);
List findByPK_usermobilephoneum(字符串phoneNum);

您找到解决方案了吗?我也面临同样的问题。提前感谢请将您的存储库界面添加到问题中。它应该是
extends crudepository
,使用自定义方法
List findByPkPhoneNum(字符串phoneNum)