我想查詢一個Cassandra表使用IN子句和Spring數據的@Query註釋。我有一個帶有last_name分區鍵和first_name集羣鍵的表。IN子句與春季數據和卡桑德拉@查詢
我有這樣的查詢工作
@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')
你嘗試過任何Collection類型嗎?設置或字符串列表而不是字符串數組? – 2015-04-02 19:53:57
這兩個列表和集合在啓動時返回類似於此的錯誤 '由...引發:java.lang.IllegalArgumentException:遇到不支持的查詢參數類型[interface java.util。設置]' – 2015-04-03 20:40:47