gpt4 book ai didi

cassandra - Apache Cassandra - 以 LIMIT 作为参数的访问器不起作用

转载 作者:行者123 更新时间:2023-12-02 23:02:30 45 4
gpt4 key购买 nike

我正在尝试将参数传递给访问器查询。我有以下内容:

@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);

有人知道为什么会发生这种情况吗?

最佳答案

limit 是保留的 CQL 关键字,不能用作命名参数。把它换成别的东西。例如:

@Query("SELECT * FROM activity WHERE user_id = :id limit :max")
Result<UserActivity> findUserActivityByUserId(@Param("id") Long ownerId, @Param("max") int limit);

关于cassandra - Apache Cassandra - 以 LIMIT 作为参数的访问器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36204647/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com