CassandraRepository - 输入“2021-01”没有可行的替代方案
CassandraRepository - no viable alternative at input '2021-01'
我想在我的 java CassandraRepository 中使用 @Query 注释执行此操作:
select * from TABLE_A where month IN
('2021-01',
'2021-02',
'2021-03',
'2021-04',
'2021-05',
'2021-06',
'2021-07',
'2021-08',
'2021-09',
'2021-10',
'2021-11',
'2021-12')
AND user_id = '1';
在我的 CassandraRepository 中:
@Query("SELECT * FROM TABLE_A WHERE user_id = ?0 AND month IN ?1")
List<UserListenCountByMonth> findByUserIdAndYear(String userId, List<String> year);
但是出现错误:
Caused by: com.datastax.driver.core.exceptions.SyntaxError: line 1:84
no viable alternative at input '2021-01' (...WHERE user_id = '1' AND [month] IN...)
我检查了调试,我的字符串列表没有问题。我错过了什么?谢谢。
旧版本的 CassandraRepository 需要在您的@Query 中使用括号。
所以,改变:
@Query("SELECT * FROM TABLE_A WHERE user_id = ?0 AND month IN ?1")
至:
@Query("SELECT * FROM TABLE_A WHERE user_id = ?0 AND month IN (?1)")
我想在我的 java CassandraRepository 中使用 @Query 注释执行此操作:
select * from TABLE_A where month IN
('2021-01',
'2021-02',
'2021-03',
'2021-04',
'2021-05',
'2021-06',
'2021-07',
'2021-08',
'2021-09',
'2021-10',
'2021-11',
'2021-12')
AND user_id = '1';
在我的 CassandraRepository 中:
@Query("SELECT * FROM TABLE_A WHERE user_id = ?0 AND month IN ?1")
List<UserListenCountByMonth> findByUserIdAndYear(String userId, List<String> year);
但是出现错误:
Caused by: com.datastax.driver.core.exceptions.SyntaxError: line 1:84 no viable alternative at input '2021-01' (...WHERE user_id = '1' AND [month] IN...)
我检查了调试,我的字符串列表没有问题。我错过了什么?谢谢。
旧版本的 CassandraRepository 需要在您的@Query 中使用括号。
所以,改变:
@Query("SELECT * FROM TABLE_A WHERE user_id = ?0 AND month IN ?1")
至:
@Query("SELECT * FROM TABLE_A WHERE user_id = ?0 AND month IN (?1)")