Apache Cassandra - 使用LIMIT作为参数无法正常工作的访问者

时间:2016-03-24 16:00:22

标签: cassandra datastax-java-driver

我正在尝试将参数传递给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);

有没有人知道为什么会这样?

1 个答案:

答案 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);