Scopes and Collections can be specified on repositories that extend DynamicProxyable using the withScope(scopeName) and withCollection(collectionName) APIs
But we are getting NoSuchMethodException
Caused by: java.lang.NoSuchMethodException: jdk.proxy2.$Proxy167.findAllById(java.lang.Object)
at java.base/java.lang.Class.getMethod(Class.java:2227)
at org.springframework.data.couchbase.repository.support.DynamicInvocationHandler.invoke(DynamicInvocationHandler.java:118)
… 42 common frames omitted
@Query("#{n1ql.selectEntity} from #{n1ql.scope} WHERE #{n1ql.filter} ORDER BY $3 ASC LIMIT $1 OFFSET $2 ")
Flux findAll(int limit, int offset,String column,String sortType);
and calling this method as
repository.withScope(“scopename”).findAll()
But it fails as below:
Caused by: java.lang.NoSuchMethodException: No such method: findAll
at org.springframework.data.couchbase.repository.support.FindMethod.internalFind(FindMethod.java:84)
at org.springframework.data.couchbase.repository.support.FindMethod.findMethod(FindMethod.java:33)
at org.springframework.data.couchbase.repository.support.DynamicInvocationHandler.invoke(DynamicInvocationHandler.java:119)
at jdk.proxy2/jdk.proxy2.$Proxy168.findAll(Unknown Source)
n1ql.selectEntity already includes the ‘from collection-name’, so you don’t need that but the collection name would need to be specified as below or otherwise.
It seems that parameterizing ORDER BY $3 $4 doesn’t work like you hoped. The $3 will be effectively replaced by a string literal instead of the property. And it seems that anything is accepted for $4(?).
If you want to simply provide strings to be replaced in the query statement (i.e. NOT sql parameter substitution) you can use #{[1]} to reference parameters (I don’t recall if it is 0-indexed or 1-indexed off the top of my head)
@Query(SELECT META(#{#n1ql.bucket}).id AS __id, META(#{#n1ql.bucket}).cas AS __cas, meta().id as id FROM #{#n1ql.bucket} WHERE #{#n1ql.filter} #{[1]})