我正在尝试使用Spring Data中的@Query注释和IN子句查询Cassandra表。我的表有一个以 last_name 为分区键、以 first_name 为聚类键。
我已经使这个查询工作正常。
@Query("SELECT * FROM people WHERE last_name=?0")
public List<People> findByLastName(String lastName);
我想要做类似的事情
@Query("SELECT * FROM people WHERE last_name=?0 AND first_name IN ?1")
public List<People> findByLastName(String lastName, String[] firstName);
我已经使用它工作了
CassandraOperations.select("SELECT * FROM people WHERE last_name=" + lastName +
" AND first_name IN (" + concatinatedNameList + ")", People.class);
因为种种原因(代码风格、测试,我保证还有更多)我更倾向于使用@Query。你有什么想法吗?
补充信息!
传递数组、集合或列表会返回Caused by: java.lang.IllegalArgumentException: encountered unsupported query parameter type [class [Ljava.lang.String;] in method public abstract
我也尝试过:
String firstName = "Joe,Jim";
@Query("SELECT * FROM people WHERE last_name=?0 AND first_name IN (?1)")
public List<People> findByLastName(String lastName, String firstName);
没有找到人,图书馆正在搜索一个名字拼接在一起的单个人 ('Joe,Jim')
String firstName = "'Joe','Jim'";
@Query("SELECT * FROM people WHERE last_name=?0 AND first_name IN (?1)")
public List<People> findByLastName(String lastName, String firstName);
没有找到相关内容,请求已被转义并以 ('''Joe'',''Jim''')
结束。
String firstName = "Joe','Jim"; // Hoping the library would just add the outer quotes, getting desperate
@Query("SELECT * FROM people WHERE last_name=?0 AND first_name IN (?1)")
public List<People> findByLastName(String lastName, String firstName);
没有找到相关内容,请求已被转义并以 ('Joe'',''Jim')
结束。
Caused by: java.lang.IllegalArgumentException: 遇到不支持的查询参数类型 [interface java.util.Set]
- Bill H