I have a stable backend working on spring boot 2.2.4.RELEASE. We do all our queries using @Query in CrudRepositoy, pretty much like this https://www.screencast.com/t/EAloISHqEvr
We had some problems with larger documents, so I decided to try migrating to most recent spring boot 2.4.1.
This caused some dependency and configuration issues due to changes in 2.3.x, but I was able to fix those.
Now the backend is working however many queries fail to work. After lots of digging we determined that broken queries are the ones that contain custom SELECT statement and META().id AS _ID, META().cas AS _CAS or the ones that return primitive type classes (boolean, long…)
I tried several different work-arounds like using different return types, different Crud repositories including playing with ReactiveCrudRepository, all leading to the same null pointer exception error in the end.
I went through lots of spring boot and CouchBase documentation and haven’t found anything that could help me identify a simple solution for this. Can anyone please help with this issue? I’d still like to hope this is some simple thing I missed like configuration and not a result of some major breaking change in CB SDK.
broken queries are the ones that contain custom SELECT statement and META().id AS _ID, META().cas AS _CAS
Use __cas instead of _CAS. Use __id instead of __ID. It’s case sensitive.
or the ones that return primitive type classes (boolean, long…)
Same thing - __cas and __id need to be included in the projection list. Although even if it executes, it will not likely result in what you want since projections to other than the ‘entity’ type are not yet implemented.
I tried the __CAS because that was the exact point where nullpointer hapened (you can see that in screenshot). We’ll try your lowercase suggestion and I’ll get back to you (but it won’t be very soon - we had to give up from upgrade due to timelines). Perhaps suggest the same solution to @iisuru in his post - it sure look like same issue.
This still remains broken in Spring Boot 2.5.1 making 2.2.13.RELEASE the last version where @Query worked properly.
I even tried building a fresh clean Spring Boot 2.5.1 application in Kotlin which I intended to use as a base for a new future project. It uses ReactiveCrudRepository instead of old thread blocking CrudRepository. I ended up with the exact same issue. As soon as I start a @Query with anything other then #{#n1ql.selectEntity} it’s game over.
Hi @jvilson - there’s nothing missing. use both __id and __cas. Or use #{n1ql.selectEntity}
These are straight from the unit tests
./src/test/java/org/springframework/data/couchbase/domain/AirportRepository.java: @Query(“Select "" AS __id, 0 AS __cas, substr(iata,0,1) as iata, count(*) as someNumber FROM #{n1ql.bucket} WHERE #{n1ql.filter} GROUP BY substr(iata,0,1)”)
./src/test/java/org/springframework/data/couchbase/domain/AirportRepository.java: @Query(“#{n1ql.selectEntity} where iata = $1”)