Hi.
I am using DynamicProxyable interface provided by the spring data couchbase to dynamically select scope for different tenant. I am facing some issues when using DynamicProxyable interface.
I am using:
- Spring boot 3.4.1
- Java 21
- Spring Data Couchbase (non-reactive)
- multimodule setup
Problems
-
Not able to use
Page<T> findAll(Pageable pageable)
Seems while executing count query it is executing in_default
scope. The plain findAll() works fine. -
using variable in repository with custom method, throws error.
public interface AttributeRepository
extends CouchbaseRepository<Attribute, String>, DynamicProxyable<AttributeRepository> {
@Query("""
#{#n1ql.selectEntity}
WHERE attribute_group_id = $groupCode
OFFSET $offset
LIMIT $limit""")
List<Attribute> getAllAttributes(String groupCode, Integer offset, Integer limit);
}
AttributeDaoImpl.class
@Override
public List<Attribute> getAllContextTenantAttributes(String attributeGroupCode, int offset, int limit) {
return attributeRepository
.withScope(getThreadContextTenantScope())
.getAllAttributes(attributeGroupCode, offset, limit);
}
Stacktrace for the problem 2
java.lang.NullPointerException: null
at java.base/java.lang.Class.isAssignableFrom(Native Method) ~[na:na]
at org.springframework.data.couchbase.repository.support.FindMethod.internalFind(FindMethod.java:77) ~[spring-data-couchbase-5.4.1.jar:5.4.1]
at org.springframework.data.couchbase.repository.support.FindMethod.findMethod(FindMethod.java:33) ~[spring-data-couchbase-5.4.1.jar:5.4.1]
at org.springframework.data.couchbase.repository.support.DynamicInvocationHandler.invoke(DynamicInvocationHandler.java:119) ~[spring-data-couchbase-5.4.1.jar:5.4.1]
at jdk.proxy3/jdk.proxy3.$Proxy148.getAllAttributes(Unknown Source) ~[na:na]
at o.c.n.p.AttributeDaoImpl.getAllContextTenantAttributes(AttributeDaoImpl.java:63) ~[data.jar:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:359) ~[spring-aop-6.2.1.jar:6.2.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196) ~[spring-aop-6.2.1.jar:6.2.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-6.2.1.jar:6.2.1]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138) ~[spring-tx-6.2.1.jar:6.2.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.2.1.jar:6.2.1]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:727) ~[spring-aop-6.2.1.jar:6.2.1]
at o.c.n.p.data.dao.impl.AttributeDaoImpl$$SpringCGLIB$$0.getAllContextTenantAttributes(<generated>) ~[data.jar:na]
at o.c.n.p.core.service.impl.AttributeServiceImpl.getAllAttributes(AttributeServiceImpl.java:57) ~[core.jar:na]
at o.c.n.p.api.handler.impl.AttributeHandlerImpl.getAllAttributes(AttributeHandlerImpl.java:61) ~[main/:na]
at o.c.n.p.api.controller.AttributeController.getAttributes(AttributeController.java:139) ~[main/:na]
Surprisingly, it stops throwing error, if I remove the attributeGroupCode from repository method call or change it to string literal instead of passing value in variable. Like:
AttributeDaoImpl.class
@Override
public List<Attribute> getAllContextTenantAttributes(String attributeGroupCode, int offset, int limit) {
return attributeRepository
.withScope(getThreadContextTenantScope())
.getAllAttributes("attributeGroupCode", offset, limit);
}
I could not generate the second problem. Any hint would be a great help.