我正在尝试将参数传递给Accessor查询。我有以下内容:
@Accessor
public interface ActivityAccessor {
@Query("SELECT * FROM activity WHERE user_id = :id limit :limit")
Result<UserActivity> findUserActivityByUserId(@Param("id") Long ownerId, @Param("limit") int limit);
}
使用以下方法调用访问器方法:
MappingManager manager = new MappingManager (getSession());
ActivityAccessor activityAccessor = manager.createAccessor(ActivityAccessor.class);
Result<UserActivity> activities = activityAccessor.findUserActivityByUserId(userId, 20);
我收到以下错误:
Caused by: com.datastax.driver.core.exceptions.SyntaxError: line 1:99 no viable alternative at input 'limit' (... LIMIT :[limit])
但是,当我更改访问器方法以显式声明限制值时,它可以正常工作:
@Query("SELECT * FROM activity WHERE user_id = :id limit 20")
Result<UserActivity> findUserActivityByUserId(@Param("id") Long ownerId);
有没有人知道为什么会这样?
答案 0 :(得分:6)
limit
是保留的CQL关键字,不能用作命名参数。改变它的东西。 e.g:
@Query("SELECT * FROM activity WHERE user_id = :id limit :max")
Result<UserActivity> findUserActivityByUserId(@Param("id") Long ownerId, @Param("max") int limit);