我是使用 Spring Data for Couchbase 的新手,我定义了这个对象
public class Building {
@NotNull
@Id
private String id;
@NotNull
@Field
private String name;
@NotNull
@Field
private String companyId;
}
我想按 ID 计算数据库中的所有元素,所以我创建了这个函数:
@Repository
@N1qlPrimaryIndexed
@ViewIndexed(designDoc = "building")
public interface BuildingRepository extends CouchbaseRepository<Building, String> {
@Query("SELECT COUNT(*) AS count FROM #{#n1ql.bucket} WHERE #{#n1ql.filter} and id = $1")
Long countBuildings(String id);
}
但我得到0,就在保存对象之后
我也试过
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} and id = $1")
Long countBuildings(String id);
但我得到了这个例外
org.springframework.data.couchbase.core.CouchbaseQueryExecutionException: Query returning a primitive type are expected to return exactly 1 result, got 0