Reactive DynamicProxyable is not working

Hi ,

Trying to implement withScope method as per the below link

https://docs.spring.io/spring-data/couchbase/docs/4.4.6/reference/html/#couchbase.collections

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

@mreiche can you please check and help?

That looks like this issue Runtime error when calling DeleteAllById(Iterable<T> list) if the repository extends DynamicProxyable · Issue #1939 · spring-projects/spring-data-couchbase · GitHub

Please use the latest version - 5.3.4

thanks it worked. But looks the user defined functions defined using @Query in the repository are still having issue. Can you please help?

@mreiche Any suggestions?

Can you show what is not working abd how it is not working?

In the repository defined a method

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

It looks like it expects all the arguments to be non-primitives, (i.e. Integer instead of int). I created a ticket DynamicProxyable works only with non-primitive arguments · Issue #1965 · spring-projects/spring-data-couchbase · GitHub . But this definition will work.

findAll(Integer limit, Integer offset,String column,String sortType)

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.

repository.withScope(“scopename”),withCollection("collectionName").findAll

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]})

Looks it is 0 indexed. After changing to non primitive it worked. thanks for the help.

Hi how to mock this repository which extends DynamicProxyable in Junit ?

I don’t mock the repositories. See the tests in GitHub - spring-projects/spring-data-couchbase: Provides support to increase developer productivity in Java when using Couchbase. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.