Join Query for working with spring boot

Hi, i am trying to write code on spring boot to use join query.
This is what i have:
@Query(
“SELECT * FROM #{#n1ql.bucket} AS f LEFT OUTER JOIN #{#n1ql.bucket} AS c ON f.category = meta( c ).id WHERE META(f).id = $1”
)
List<?> findByQuery(String id);

And I got error like this:

java.lang.NullPointerException\n\tat org.springframework.data.couchbase.core.ReactiveFindByQueryOperationSupport$ReactiveFindByQuerySupport.lambda$null$1(ReactiveFindByQueryOperationSupport.java:94)\n\tat reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:100)\n\tat reactor.core.publisher.MonoFlatMapMany$FlatMapManyInner.onNext(MonoFlatMapMany.java:242)\n\tat reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:114)\n\tat reactor.core.publisher.EmitterProcessor.drain(EmitterProcessor.java:426)

can someone point out what is wrong with my code? Thanks!

@eln Does your query work from Query Work Bench of the UI?

yes, it works from Query Work Bench.

Hi @ein -

queries need to have __cas and __id projected.

@Query("SELECT 0 as “+TemplateUtils.SELECT_CAS +”, ‘’ as "’ as “+TemplateUtils.SELECT_ID+” , MAX(…

public class TemplateUtils {
public static final String SELECT_ID = “__id”;
public static final String SELECT_CAS = “__cas”;See https://forums.couchbase.com/t/unable-to-use-n1ql-query-in-query-annotation-with-max-function-in-spring-data-couchbase-4-1-5/29776

I’ve opened NullPointerException in @Query that do not project __cas . Should check for this explicitly · Issue #1097 · spring-projects/spring-data-couchbase · GitHub to handle this better.

Hi @mreiche
do i have to use reactive repository to handle the join query or can i just use the couchbase repository?

Either will work. The CouchbaseRepository uses the ReactiveCouchbaseRepository.

it works, thanks for helping!